import { type SchemaRules } from '@adonisjs/lucid/types/schema_generator'

/**
 * Override de types pour les colonnes que Lucid n'arrive pas à inférer
 * depuis l'introspection PG (ex. ENUMs natifs et jsonb → tapés `any`).
 */
export default {
  tables: {
    plan_steps: {
      columns: {
        tone: {
          tsType: "'amical' | 'courtois' | 'ferme' | 'mise_en_demeure'",
        },
      },
    },
    invoices: {
      columns: {
        status: {
          tsType:
            "'pending' | 'awaiting_user_confirmation' | 'in_relance' | 'paid' | 'litigation' | 'cancelled'",
        },
      },
    },
    activity_events: {
      columns: {
        kind: {
          tsType:
            "'relance_sent' | 'invoice_paid' | 'invoice_imported' | 'warning_drafted'",
        },
        meta: {
          tsType:
            "{ invoiceId?: string; clientId?: string; planStepOrder?: number; [k: string]: unknown }",
        },
      },
    },
    relance_tasks: {
      columns: {
        status: {
          tsType: "'scheduled' | 'sent' | 'cancelled' | 'failed'",
        },
      },
    },
    checkin_tasks: {
      columns: {
        status: {
          tsType: "'scheduled' | 'sent' | 'answered' | 'expired'",
        },
        answer: {
          tsType: "'paid' | 'still_pending' | null",
        },
      },
    },
    import_drafts: {
      columns: {
        status: {
          tsType: "'pending' | 'validated' | 'skipped'",
        },
        // jsonb des champs extraits par l'OCR. La forme est garantie par
        // le validator Vine côté entrée et par le service côté seed.
        extracted: {
          tsType:
            "{ clientId: string | null; clientName: string; clientEmail: string | null; numero: string; amountTtcCents: number; issueDate: string; dueDate: string; planId: string | null }",
        },
        edited: {
          tsType:
            "{ clientId: string | null; clientName: string; clientEmail: string | null; numero: string; amountTtcCents: number; issueDate: string; dueDate: string; planId: string | null }",
        },
        // Confiance par champ — 0..1. Partial parce que l'OCR n'a pas
        // toujours toutes les confiances.
        confidence: {
          tsType:
            "Partial<{ clientId: number; clientName: number; clientEmail: number; numero: number; amountTtcCents: number; issueDate: number; dueDate: number; planId: number }>",
        },
      },
    },
  },
} satisfies SchemaRules
