# -*- coding: utf-8 -*-
"""STEP 6 — AI draft wizard (the UI walkthrough for single-shot drafting)."""

from odoo import fields, models


class FamilyLawAIDraftWizard(models.TransientModel):
    _name = "familylaw.ai.draft.wizard"
    _description = "AI Draft Wizard"

    proceeding_id = fields.Many2one(
        "familylaw.proceeding", string="Proceeding", required=True,
    )
    document_type = fields.Selection(
        selection=[
            ("pleading", "Pleading / Motion"),
            ("form", "Florida Supreme Court Form"),
            ("affidavit", "Affidavit"),
            ("order", "Proposed Order"),
            ("correspondence", "Correspondence"),
            ("notice", "Notice"),
            ("other", "Other"),
        ],
        default="pleading",
        required=True,
    )
    doc_name = fields.Char(string="Document Title")
    instruction = fields.Text(
        string="Instruction",
        required=True,
        help="What to assemble, in plain language. Facts come from the matter.",
    )

    def action_generate(self):
        self.ensure_one()
        doc = self.env["familylaw.document"].ai_assemble(
            self.proceeding_id, self.document_type, self.instruction,
            name=self.doc_name or False,
        )
        return {
            "type": "ir.actions.act_window",
            "res_model": "familylaw.document",
            "res_id": doc.id,
            "view_mode": "form",
            "target": "current",
        }
