export type UserStatut = "en_attente" | "valide" | "refuse";
export type UserRole = "client" | "admin";
export type OrderStatut = "recue" | "commandee" | "prete" | "recuperee" | "annulee";
export type DocumentType =
  | "carte_proprio"
  | "attestation_fabricant"
  | "attestation_honneur"
  | "justif_domicile"
  | "cni_recto"
  | "cni_verso"
  | "photo_cle_recto"
  | "photo_cle_verso"
  | "cle_originale"
  | "autre";

export interface Profile {
  id: string;
  societe: string;
  siret: string;
  prenom: string;
  nom: string;
  telephone: string;
  role: UserRole;
  statut: UserStatut;
  created_at: string;
  validated_at: string | null;
  validated_by: string | null;
}

export interface Product {
  id: string;
  fabricant: string;
  modele: string;
  prix_ht: number | null;
  prix_ttc_conseille: number | null;
  image_url: string | null;
  numero_cle_obligatoire: boolean;
  carte_proprio_obligatoire: boolean;
  attestation_fabricant_si_pas_carte: boolean;
  attestation_honneur_si_pas_carte: boolean;
  justif_domicile_si_pas_carte: boolean;
  cni_si_pas_carte: boolean;
  renouvellement_carte_si_perdue: boolean;
  carte_renouvelable: boolean;
  frais_renouvellement_ht: number | null;
  commande_bloquee_sans_carte: boolean;
  cle_originale_si_pas_carte: boolean;
  photo_cle_obligatoire: boolean;
  commentaire: string | null;
  actif: boolean;
  created_at: string;
}

export interface Order {
  id: string;
  user_id: string;
  numero_commande: string;
  statut: OrderStatut;
  montant_ht_total: number | null;
  notes_admin: string | null;
  created_at: string;
  commandee_at: string | null;
  prete_at: string | null;
  recuperee_at: string | null;
  sms_envoye_at: string | null;
}

export interface OrderItem {
  id: string;
  order_id: string;
  product_id: string;
  quantite: number;
  numero_cle_grave: string | null;
  has_carte_proprio: boolean;
  prix_ht_unitaire: number;
  rules_snapshot: unknown;
}

export interface DocumentRow {
  id: string;
  order_item_id: string;
  type: DocumentType;
  storage_path: string;
  filename: string | null;
  uploaded_at: string;
}

export interface Database {
  public: {
    Tables: {
      profiles: { Row: Profile; Insert: Partial<Profile> & { id: string; societe: string; siret: string; prenom: string; nom: string; telephone: string }; Update: Partial<Profile> };
      products: { Row: Product; Insert: Partial<Product> & { fabricant: string; modele: string }; Update: Partial<Product> };
      orders: { Row: Order; Insert: Partial<Order> & { user_id: string; numero_commande: string }; Update: Partial<Order> };
      order_items: { Row: OrderItem; Insert: Partial<OrderItem> & { order_id: string; product_id: string; prix_ht_unitaire: number }; Update: Partial<OrderItem> };
      documents: { Row: DocumentRow; Insert: Partial<DocumentRow> & { order_item_id: string; type: DocumentType; storage_path: string }; Update: Partial<DocumentRow> };
      sms_logs: {
        Row: {
          id: string;
          order_id: string | null;
          destinataire: string;
          message: string;
          provider_response: unknown;
          statut: "envoye" | "echec" | null;
          created_at: string;
        };
        Insert: {
          order_id?: string | null;
          destinataire: string;
          message: string;
          provider_response?: unknown;
          statut?: "envoye" | "echec" | null;
        };
        Update: Partial<{ statut: "envoye" | "echec"; provider_response: unknown }>;
      };
    };
    Views: Record<string, never>;
    Functions: Record<string, never>;
    Enums: Record<string, never>;
  };
}
