// ─── Standard Thai Legal Obligation Rules ─────────────────────────────────────
// Seed data for the obligation_rules collection.
// These are the known standard rules for Thai practice areas.
// RAG Agent will add/update entries as laws change.
// Attorney confirmation of proposals validates and refines these over time.

export const STANDARD_OBLIGATION_RULES = [

  // ── Thai Immigration ───────────────────────────────────────────────────────

  {
    obligationKey:    'tm47_90day_report',
    name:             '90-Day Reporting (TM.47)',
    description:      'Foreigners staying in Thailand on a non-immigrant visa must report to Immigration every 90 days. Failure to report within the window incurs a 2,000 THB fine.',
    practiceArea:     'immigration',
    matterSubTypes:   ['retirement_visa', 'non_immigrant_o', 'non_immigrant_b', 'work_permit', 'long_stay', 'education_visa'],
    jurisdiction:     'th',
    anchorField:      'client.arrivalDate',
    offsetDays:       90,
    intervalDays:     90,
    maxRecurrences:   undefined,
    reminderLeadDays: 14,
    linkedFormIds:    [],    // TM.47 — populated after form library seeded
    notes:            'Can be done online via immigration.go.th or in person. Window is 15 days before or 7 days after the 90th day.',
    isActive:         true,
    createdBy:        'system',
  },

  {
    obligationKey:    'tm7_annual_extension',
    name:             'Annual Visa Extension (TM.7)',
    description:      'Non-immigrant visa extension must be applied for before visa expiry. For retirement: proof of 800k THB in Thai bank or 65k THB/month income required.',
    practiceArea:     'immigration',
    matterSubTypes:   ['retirement_visa', 'non_immigrant_o', 'non_immigrant_b', 'education_visa'],
    jurisdiction:     'th',
    anchorField:      'client.visaExpiry',
    offsetDays:       -30,
    intervalDays:     365,
    maxRecurrences:   undefined,
    reminderLeadDays: 30,
    linkedFormIds:    [],    // TM.7
    notes:            'Apply at local immigration office. Bring passport, TM.30 (if applicable), proof of funds, photos, and landlord letter.',
    isActive:         true,
    createdBy:        'system',
  },

  {
    obligationKey:    'work_permit_renewal',
    name:             'Work Permit Renewal',
    description:      'Work permit must be renewed before expiry. Requires current employer sponsorship, updated company documents, and tax clearance.',
    practiceArea:     'immigration',
    matterSubTypes:   ['work_permit', 'non_immigrant_b'],
    jurisdiction:     'th',
    anchorField:      'client.permitExpiry',
    offsetDays:       -30,
    intervalDays:     365,
    maxRecurrences:   undefined,
    reminderLeadDays: 30,
    linkedFormIds:    [],    // WP.1, WP.10
    notes:            'Apply at Department of Employment. Must be done concurrently with visa extension if both expire on same date.',
    isActive:         true,
    createdBy:        'system',
  },

  {
    obligationKey:    'tm30_notification',
    name:             'TM.30 House Master Notification',
    description:      'House master / hotel must notify immigration within 24 hours of a foreigner staying at the property. Attorney should ensure client has confirmed TM.30 filing by landlord.',
    practiceArea:     'immigration',
    matterSubTypes:   ['retirement_visa', 'non_immigrant_o', 'non_immigrant_b', 'work_permit', 'long_stay'],
    jurisdiction:     'th',
    anchorField:      'client.arrivalDate',
    offsetDays:       1,
    intervalDays:     undefined,
    maxRecurrences:   1,
    reminderLeadDays: 0,
    linkedFormIds:    [],
    notes:            'Technically the landlord\'s obligation but failure affects the foreign national. Confirm with client that landlord has filed.',
    isActive:         true,
    createdBy:        'system',
  },

  // ── Thai Corporate ────────────────────────────────────────────────────────

  // ── Annual Compliance cycle (BOD → AGM → DBD → Tax) ──────────────────────
  // anchorField: 'matter.annualCompliance.yearEndDate' is the statutory base.
  // The annual-compliance module writes this field on the matter document so
  // the deadline resolver can pick it up. All four rules chain from year-end.

  {
    obligationKey:    'thai_company_annual_agm',
    name:             'Annual General Meeting (AGM) — Hold by deadline',
    description:      'Thai limited companies must hold an AGM within 4 months of financial year-end. The BOD meeting must be held first to formally resolve calling the AGM.',
    practiceArea:     'corporate',
    matterSubTypes:   ['company_registration', 'company_maintenance', 'boi_company', 'annual_compliance'],
    jurisdiction:     'th',
    anchorField:      'matter.annualCompliance.yearEndDate',
    offsetDays:       120,         // year-end + 4 months = April 30 for Dec 31 year-end
    intervalDays:     365,
    maxRecurrences:   undefined,
    reminderLeadDays: 30,
    linkedFormIds:    [],          // populated by annual-compliance service after documents generated
    notes:            'The AGM must approve: previous minutes, financial statements, shareholder list (DBD), director rotation, auditor appointment. Deadline for Dec 31 year-end = April 30.',
    isActive:         true,
    createdBy:        'system',
  },

  {
    obligationKey:    'thai_company_dbd_shareholders',
    name:             'File Shareholder List with DBD (BOJ.5)',
    description:      'Updated shareholder list (Bor.Or.Jor.5) must be filed with the Department of Business Development within 14 days of the AGM.',
    practiceArea:     'corporate',
    matterSubTypes:   ['company_registration', 'company_maintenance', 'boi_company', 'annual_compliance'],
    jurisdiction:     'th',
    anchorField:      'matter.annualCompliance.agmDate',
    offsetDays:       14,          // AGM date + 14 days
    intervalDays:     365,
    maxRecurrences:   undefined,
    reminderLeadDays: 7,
    linkedFormIds:    [],          // th-dbd-bor5 form
    notes:            'File via DBD e-Filing portal (efiling.dbd.go.th) or in person at DBD office. Requires authorised director signature.',
    isActive:         true,
    createdBy:        'system',
  },

  {
    obligationKey:    'thai_company_dbd_financials',
    name:             'File Audited Financial Statements with DBD',
    description:      'Audited financial statements must be submitted to the Department of Business Development within 1 month of AGM approval.',
    practiceArea:     'corporate',
    matterSubTypes:   ['company_registration', 'company_maintenance', 'boi_company', 'annual_compliance'],
    jurisdiction:     'th',
    anchorField:      'matter.annualCompliance.agmDate',
    offsetDays:       30,          // AGM date + 1 month (approx 30 days)
    intervalDays:     365,
    maxRecurrences:   undefined,
    reminderLeadDays: 14,
    linkedFormIds:    [],
    notes:            'File via DBD e-Filing. Auditor must be a licensed CPA (ผู้สอบบัญชีรับอนุญาต). Late filing: 2,000 THB fine; directors liable.',
    isActive:         true,
    createdBy:        'system',
  },

  {
    obligationKey:    'thai_company_tax_pnd50',
    name:             'Corporate Tax Return (PND.50)',
    description:      'Annual corporate income tax return (Por.Ngor.Dor.50) must be filed with the Revenue Department within 150 days of financial year-end.',
    practiceArea:     'corporate',
    matterSubTypes:   ['company_registration', 'company_maintenance', 'boi_company', 'annual_compliance'],
    jurisdiction:     'th',
    anchorField:      'matter.annualCompliance.yearEndDate',
    offsetDays:       150,         // year-end + 150 days = May 30 for Dec 31 year-end
    intervalDays:     365,
    maxRecurrences:   undefined,
    reminderLeadDays: 21,
    linkedFormIds:    [],          // PND.50 form
    notes:            'Filed by the accountant/tax advisor. Coordinate with accounting firm 4–6 weeks before deadline. Late filing: 1.5× tax or 5,000 THB minimum fine.',
    isActive:         true,
    createdBy:        'system',
  },

  {
    obligationKey:    'thai_company_financial_statements',
    name:             'Annual Financial Statements Filing (DBD) — Legacy rule',
    description:      'Superseded by thai_company_dbd_financials which uses AGM date as anchor. Kept for backwards compatibility with existing deadline records.',
    practiceArea:     'corporate',
    matterSubTypes:   ['company_registration', 'company_maintenance', 'boi_company'],
    jurisdiction:     'th',
    anchorField:      'matter.openedDate',
    offsetDays:       150,
    intervalDays:     365,
    maxRecurrences:   undefined,
    reminderLeadDays: 21,
    linkedFormIds:    [],
    notes:            'Use thai_company_dbd_financials for new annual_compliance matters.',
    isActive:         false,       // disabled — replaced by more precise rule above
    createdBy:        'system',
  },

  {
    obligationKey:    'boi_annual_report',
    name:             'BOI Annual Report',
    description:      'BOI-promoted companies must submit an annual report of operations and machinery use to the Board of Investment.',
    practiceArea:     'corporate',
    matterSubTypes:   ['boi_company', 'boi_promotion'],
    jurisdiction:     'th-boi',
    anchorField:      'matter.openedDate',
    offsetDays:       90,
    intervalDays:     365,
    maxRecurrences:   undefined,
    reminderLeadDays: 21,
    linkedFormIds:    [],
    notes:            'Submit via BOI One Stop Service Center or online portal. Late filing risks BOI privilege suspension.',
    isActive:         true,
    createdBy:        'system',
  },

  // ── Thai Property ─────────────────────────────────────────────────────────

  {
    obligationKey:    'lease_renewal_reminder',
    name:             'Lease Renewal Reminder',
    description:      'Long-term lease (30-year) renewal must be negotiated before expiry. Registered at Land Department.',
    practiceArea:     'property',
    matterSubTypes:   ['lease', 'long_term_lease'],
    jurisdiction:     'th',
    anchorField:      'client.visaExpiry',   // using visaExpiry as proxy — will be superseded by lease expiry field
    offsetDays:       -180,
    intervalDays:     undefined,
    maxRecurrences:   1,
    reminderLeadDays: 30,
    linkedFormIds:    [],
    notes:            'Thai law limits leases to 30 years. Renewal must be re-registered at Land Department. Start negotiations 6+ months out.',
    isActive:         true,
    createdBy:        'system',
  },
]
