# Generated by Django 5.2.10 on 2026-03-30 12:55

import django.db.models.deletion
import encrypted_fields.fields
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='ClientIdentity',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(help_text="Descriptive name, e.g. 'Bank API mTLS Cert 2026', 'SFTP Jump Host Key', 'Prod DB Client Cert'", max_length=100)),
                ('key_type', models.CharField(choices=[('rsa', 'RSA'), ('ecdsa', 'ECDSA'), ('ed25519', 'Ed25519'), ('dsa', 'DSA'), ('certificate', 'X.509 Certificate + Private Key')], help_text='Type of key. Helps with validation and usage hints.', max_length=20)),
                ('private_key', encrypted_fields.fields.EncryptedTextField(help_text='PEM-formatted private key (with -----BEGIN ...----- headers). May be encrypted.')),
                ('passphrase', encrypted_fields.fields.EncryptedCharField(blank=True, help_text='Passphrase if the private key is encrypted', max_length=255, null=True)),
                ('certificate_chain', encrypted_fields.fields.EncryptedTextField(blank=True, help_text='Full PEM chain: client cert + intermediates (for mTLS). Optional for SSH.', null=True)),
                ('expected_server_fingerprint', models.CharField(blank=True, default='', help_text='SHA256 fingerprint of expected server cert (e.g. SHA256:abc...def). Used to prevent MITM even when verify_ssl=True.', max_length=255)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name_plural': 'Client Identities',
            },
        ),
        migrations.CreateModel(
            name='TokenFlow',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('flow_type', models.CharField(choices=[('no_flow', 'No Flow'), ('client_credentials', 'Client Credentials')], default='no_flow', max_length=40)),
                ('name', models.CharField(max_length=255)),
                ('client_id', models.CharField(blank=True, max_length=255)),
                ('client_secret', encrypted_fields.fields.EncryptedCharField(blank=True, max_length=255, null=True)),
                ('token_url', models.URLField(blank=True, null=True)),
                ('scope', models.CharField(blank=True, max_length=1000)),
                ('access_token_field', models.CharField(blank=True, default='access_token', help_text='JSON field name for the access token (default: access_token)', max_length=100)),
                ('expires_in_field', models.CharField(blank=True, default='expires_in', help_text="JSON field name for expires_in seconds (default: expires_in). Use '' to disable expiration.", max_length=100)),
                ('cached_token', encrypted_fields.fields.EncryptedCharField(blank=True, max_length=2000, null=True)),
                ('cached_token_expires', models.DateTimeField(blank=True, null=True)),
                ('client_identity', models.ForeignKey(blank=True, help_text='Client key/cert used when contacting token endpoint (e.g. mTLS for OAuth)', null=True, on_delete=django.db.models.deletion.PROTECT, to='django_filip.clientidentity')),
            ],
            options={
                'verbose_name_plural': 'Authentication Flows',
            },
        ),
        migrations.CreateModel(
            name='Authentication',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('auth_type', models.CharField(choices=[('api_key', 'Api Key'), ('basic', 'Basic'), ('bearer_token', 'Bearer Token'), ('ssh_key', 'Ssh Key')], db_index=True, max_length=50)),
                ('name', models.CharField(max_length=255)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('api_key_value', encrypted_fields.fields.EncryptedCharField(blank=True, max_length=500, null=True)),
                ('api_key_header', models.CharField(blank=True, default='X-API-Key', max_length=100)),
                ('basic_username', models.CharField(blank=True, default='', max_length=255)),
                ('basic_password', encrypted_fields.fields.EncryptedCharField(blank=True, max_length=255, null=True)),
                ('bearer_token', encrypted_fields.fields.EncryptedCharField(blank=True, max_length=2000, null=True)),
                ('bearer_expires_at', models.DateTimeField(blank=True, null=True)),
                ('verify_server_cert', models.BooleanField(default=True, help_text='If False, disables server certificate validation (dangerous — use only temporarily)')),
                ('client_identity', models.ForeignKey(blank=True, help_text='Client key/cert used for actual API calls, SFTP session, or DB connection', null=True, on_delete=django.db.models.deletion.PROTECT, to='django_filip.clientidentity')),
                ('token_flow', models.ForeignKey(blank=True, help_text='Optional token obtaining flow (most commonly Client Credentials)', null=True, on_delete=django.db.models.deletion.PROTECT, to='django_filip.tokenflow')),
            ],
        ),
        migrations.CreateModel(
            name='Connection',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('type', models.CharField(choices=[('api', 'Api'), ('sftp', 'Sftp'), ('mssql', 'Mssql')], max_length=50)),
                ('name', models.CharField(max_length=255)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('host', models.CharField(max_length=255)),
                ('port', models.IntegerField(blank=True, help_text='e.g., 80/443 for API, 22 for SFTP, 1433 for MSSQL, 5432 for PostgreSQL, 8080 for internal API etc.', null=True)),
                ('timeout_seconds', models.PositiveIntegerField(blank=True, null=True)),
                ('expected_sftp_host_key_fingerprint', models.CharField(blank=True, default='', help_text='For SFTP/SSH: expected SHA256 host key fingerprint (e.g. SHA256:xxx). Enforces known host verification.', max_length=255)),
                ('authentication', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='django_filip.authentication')),
            ],
            options={
                'verbose_name': 'Connection',
                'verbose_name_plural': 'Connections',
                'ordering': ['type', 'name'],
                'unique_together': {('type', 'name')},
            },
        ),
    ]
