/**
 * Stock Form Library — Thai Government & Standard Legal Forms
 *
 * Three fill modes:
 *   'coordinate'    — draw text at x/y positions on a downloaded blank PDF
 *   'acroform'      — fill PDF AcroForm field names (PDF must have an AcroForm layer)
 *   'html-template' — render an HTML template to PDF via headless Chrome (complex bilingual docs)
 *
 * Source URLs point to the official issuing authority's public download.
 * PDFs are fetched on first use and cached at uploads/form-templates/stock/.
 *
 * needsCalibration: true  → coordinates are estimated; verify against actual PDF before production use.
 * needsCalibration: false → coordinates/field names verified against the current official PDF version.
 *
 * ─── How to calibrate a coordinate-mode form ────────────────────────────────
 * 1. Download the PDF from sourceUrl.
 * 2. Open in any PDF viewer. The pdf-lib coordinate origin is bottom-left of each page.
 *    Page height for A4 = 841.89 pts. So y = 841.89 - (distance from top in pts).
 * 3. Use pdfinfo / pdftotext -bbox to measure field positions, or use the admin
 *    field-mapper UI (click to place) once built.
 * ────────────────────────────────────────────────────────────────────────────
 */

export interface StockFormField {
  fieldId: string
  label: string
  dataSource: string
  staticValue?: string
  dateFormat?: string
  maxLength?: number
  // AcroForm mode
  acroFieldName?: string
  // Coordinate mode
  page?: number
  x?: number
  y?: number
  fontSize?: number
}

export interface StockFormDefinition {
  stockId: string                   // stable, never change this
  name: string
  nameLocal: string                 // Thai name
  description: string
  practiceArea: string
  sourceUrl?: string                // primary official download URL (not required for html-template)
  fallbackUrls?: string[]           // alternative sources if primary fails
  fillMode: 'coordinate' | 'acroform' | 'html-template'
  needsCalibration: boolean
  fields: StockFormField[]
  notes?: string
}

// ─────────────────────────────────────────────────────────────────────────────
// IMMIGRATION FORMS — กองตรวจคนเข้าเมือง (Immigration Bureau)
// ─────────────────────────────────────────────────────────────────────────────

const TM7: StockFormDefinition = {
  stockId: 'th-immigration-tm7',
  name: 'TM.7 — Application for Extension of Stay',
  nameLocal: 'ตม.7 — คำร้องขอต่ออายุการอนุญาตอยู่ในราชอาณาจักร',
  description: 'Standard application to extend a temporary stay permit in Thailand. Required for all non-immigrant visa holders at 90-day intervals.',
  practiceArea: 'immigration',
  sourceUrl: 'https://www.immigration.go.th/download/1593062399_tm7.pdf',
  fallbackUrls: [
    'https://www.immigration.go.th/download/tm7.pdf',
  ],
  fillMode: 'coordinate',
  needsCalibration: true,
  notes: 'A4, 2 pages. Page 1 is the application; page 2 is the officer copy. Fill page 1 only.',
  fields: [
    // ── Page 1 — Applicant details ──
    { fieldId: 'applicant_firstname',   label: 'First name',              dataSource: 'client.firstName',     page: 1, x: 165, y: 668, fontSize: 10 },
    { fieldId: 'applicant_lastname',    label: 'Last name / Family name', dataSource: 'client.lastName',      page: 1, x: 380, y: 668, fontSize: 10 },
    { fieldId: 'nationality',           label: 'Nationality',             dataSource: 'client.nationality',   page: 1, x: 165, y: 640, fontSize: 10 },
    { fieldId: 'dob',                   label: 'Date of birth',           dataSource: 'client.dateOfBirth',   page: 1, x: 165, y: 612, fontSize: 10, dateFormat: 'DD/MM/YYYY' },
    { fieldId: 'passport_no',           label: 'Passport number',         dataSource: 'client.passportNumber', page: 1, x: 350, y: 612, fontSize: 10 },
    { fieldId: 'visa_type',             label: 'Visa type / Category',    dataSource: 'client.visaType',      page: 1, x: 165, y: 584, fontSize: 10 },
    { fieldId: 'visa_number',           label: 'Visa / Permit number',    dataSource: 'client.visaNumber',    page: 1, x: 350, y: 584, fontSize: 10 },
    { fieldId: 'current_permit_expiry', label: 'Current permit expiry',   dataSource: 'client.visaExpiry',    page: 1, x: 165, y: 556, fontSize: 10, dateFormat: 'DD/MM/YYYY' },
    { fieldId: 'address_in_thailand',   label: 'Address in Thailand',     dataSource: 'client.address',       page: 1, x: 165, y: 500, fontSize: 10 },
    { fieldId: 'purpose_of_stay',       label: 'Purpose of stay',         dataSource: 'matter.title',         page: 1, x: 165, y: 472, fontSize: 10, maxLength: 60 },
    { fieldId: 'signature_date',        label: 'Date of application',     dataSource: 'static',               page: 1, x: 380, y: 180, fontSize: 10, staticValue: '___/___/______' },
  ],
}

const TM8: StockFormDefinition = {
  stockId: 'th-immigration-tm8',
  name: 'TM.8 — 90-Day Presence Notification',
  nameLocal: 'ตม.8 — แบบแจ้งการอยู่ในราชอาณาจักรเกิน 90 วัน',
  description: 'Mandatory 90-day reporting form for foreigners staying in Thailand. Must be submitted every 90 days if no departure occurs.',
  practiceArea: 'immigration',
  sourceUrl: 'https://www.immigration.go.th/download/1593062399_tm8.pdf',
  fillMode: 'coordinate',
  needsCalibration: true,
  fields: [
    { fieldId: 'firstname',       label: 'First name',         dataSource: 'client.firstName',      page: 1, x: 165, y: 650, fontSize: 10 },
    { fieldId: 'lastname',        label: 'Last name',          dataSource: 'client.lastName',       page: 1, x: 380, y: 650, fontSize: 10 },
    { fieldId: 'nationality',     label: 'Nationality',        dataSource: 'client.nationality',    page: 1, x: 165, y: 622, fontSize: 10 },
    { fieldId: 'passport_no',     label: 'Passport number',    dataSource: 'client.passportNumber', page: 1, x: 165, y: 594, fontSize: 10 },
    { fieldId: 'visa_type',       label: 'Visa type',          dataSource: 'client.visaType',       page: 1, x: 350, y: 594, fontSize: 10 },
    { fieldId: 'current_address', label: 'Address in Thailand',dataSource: 'client.address',        page: 1, x: 165, y: 538, fontSize: 10 },
  ],
}

const TM28: StockFormDefinition = {
  stockId: 'th-immigration-tm28',
  name: 'TM.28 — Alien Residence Notification (by Alien)',
  nameLocal: 'ตม.28 — แบบแจ้งที่พักอาศัยของคนต่างด้าว',
  description: 'Notification filed by the foreign national when they take up temporary residence at an address. Required within 24 hours of moving.',
  practiceArea: 'immigration',
  sourceUrl: 'https://www.immigration.go.th/download/1593062399_tm28.pdf',
  fillMode: 'coordinate',
  needsCalibration: true,
  fields: [
    { fieldId: 'firstname',     label: 'First name',          dataSource: 'client.firstName',      page: 1, x: 165, y: 660, fontSize: 10 },
    { fieldId: 'lastname',      label: 'Last name',           dataSource: 'client.lastName',       page: 1, x: 380, y: 660, fontSize: 10 },
    { fieldId: 'nationality',   label: 'Nationality',         dataSource: 'client.nationality',    page: 1, x: 165, y: 632, fontSize: 10 },
    { fieldId: 'passport_no',   label: 'Passport number',     dataSource: 'client.passportNumber', page: 1, x: 165, y: 604, fontSize: 10 },
    { fieldId: 'dob',           label: 'Date of birth',       dataSource: 'client.dateOfBirth',    page: 1, x: 350, y: 604, fontSize: 10, dateFormat: 'DD/MM/YYYY' },
    { fieldId: 'address',       label: 'Address staying at',  dataSource: 'client.address',        page: 1, x: 165, y: 550, fontSize: 10 },
    { fieldId: 'visa_expiry',   label: 'Permitted to stay until', dataSource: 'client.visaExpiry', page: 1, x: 165, y: 522, fontSize: 10, dateFormat: 'DD/MM/YYYY' },
  ],
}

const TM30: StockFormDefinition = {
  stockId: 'th-immigration-tm30',
  name: 'TM.30 — Alien Accommodation Notification (by House Owner)',
  nameLocal: 'ตม.30 — แบบแจ้งการเข้าพักของคนต่างด้าว',
  description: 'Filed by the house/condo owner or hotel within 24 hours of a foreign national taking up residence. Failure to file results in fines for the property owner.',
  practiceArea: 'immigration',
  sourceUrl: 'https://www.immigration.go.th/download/1593062399_tm30.pdf',
  fillMode: 'coordinate',
  needsCalibration: true,
  notes: 'Fields on this form refer to the property owner, not the client. The "alien" section uses client fields.',
  fields: [
    // Alien (client) section
    { fieldId: 'alien_firstname',   label: 'Alien first name',        dataSource: 'client.firstName',      page: 1, x: 165, y: 580, fontSize: 10 },
    { fieldId: 'alien_lastname',    label: 'Alien last name',         dataSource: 'client.lastName',       page: 1, x: 380, y: 580, fontSize: 10 },
    { fieldId: 'alien_nationality', label: 'Alien nationality',       dataSource: 'client.nationality',    page: 1, x: 165, y: 552, fontSize: 10 },
    { fieldId: 'alien_passport',    label: 'Alien passport number',   dataSource: 'client.passportNumber', page: 1, x: 165, y: 524, fontSize: 10 },
    { fieldId: 'alien_visa_type',   label: 'Alien visa type',         dataSource: 'client.visaType',       page: 1, x: 350, y: 524, fontSize: 10 },
    { fieldId: 'alien_visa_expiry', label: 'Alien permit expiry',     dataSource: 'client.visaExpiry',     page: 1, x: 165, y: 496, fontSize: 10, dateFormat: 'DD/MM/YYYY' },
    { fieldId: 'property_address',  label: 'Property address',        dataSource: 'client.address',        page: 1, x: 165, y: 440, fontSize: 10 },
  ],
}

const TM47: StockFormDefinition = {
  stockId: 'th-immigration-tm47',
  name: 'TM.47 — Application for Re-Entry Permit',
  nameLocal: 'ตม.47 — คำขออนุญาตเดินทางกลับเข้ามาในราชอาณาจักรอีก',
  description: 'Re-entry permit application. Required before departing Thailand to preserve an existing long-stay visa. Single or multiple re-entry options.',
  practiceArea: 'immigration',
  sourceUrl: 'https://www.immigration.go.th/download/1593062399_tm47.pdf',
  fillMode: 'coordinate',
  needsCalibration: true,
  fields: [
    { fieldId: 'firstname',       label: 'First name',           dataSource: 'client.firstName',       page: 1, x: 165, y: 658, fontSize: 10 },
    { fieldId: 'lastname',        label: 'Last name',            dataSource: 'client.lastName',        page: 1, x: 380, y: 658, fontSize: 10 },
    { fieldId: 'nationality',     label: 'Nationality',          dataSource: 'client.nationality',     page: 1, x: 165, y: 630, fontSize: 10 },
    { fieldId: 'dob',             label: 'Date of birth',        dataSource: 'client.dateOfBirth',     page: 1, x: 165, y: 602, fontSize: 10, dateFormat: 'DD/MM/YYYY' },
    { fieldId: 'passport_no',     label: 'Passport number',      dataSource: 'client.passportNumber',  page: 1, x: 165, y: 574, fontSize: 10 },
    { fieldId: 'current_permit',  label: 'Current permit number',dataSource: 'client.visaNumber',      page: 1, x: 350, y: 574, fontSize: 10 },
    { fieldId: 'permit_expiry',   label: 'Permit expires',       dataSource: 'client.visaExpiry',      page: 1, x: 165, y: 546, fontSize: 10, dateFormat: 'DD/MM/YYYY' },
    { fieldId: 'address',         label: 'Address in Thailand',  dataSource: 'client.address',         page: 1, x: 165, y: 490, fontSize: 10 },
  ],
}

// ─────────────────────────────────────────────────────────────────────────────
// WORK PERMIT FORMS — กรมการจัดหางาน (Department of Employment)
// ─────────────────────────────────────────────────────────────────────────────

const WP1: StockFormDefinition = {
  stockId: 'th-doe-wp1',
  name: 'WP.1 — Application for Work Permit',
  nameLocal: 'คำขออนุญาตทำงาน (ใบอนุญาตทำงาน)',
  description: 'Initial work permit application form. Filed by the employer on behalf of the foreign employee. Required before a foreign national may commence work in Thailand.',
  practiceArea: 'immigration',
  sourceUrl: 'https://www.doe.go.th/prd/assets/upload/files/alien_th/wp_1.pdf',
  fallbackUrls: [
    'https://www.doe.go.th/wp_1.pdf',
  ],
  fillMode: 'coordinate',
  needsCalibration: true,
  notes: 'Employer details (company name, address, registration) must be entered manually. This form auto-fills the foreign employee (client) section.',
  fields: [
    { fieldId: 'employee_firstname',   label: 'Employee first name',     dataSource: 'client.firstName',      page: 1, x: 165, y: 620, fontSize: 10 },
    { fieldId: 'employee_lastname',    label: 'Employee last name',      dataSource: 'client.lastName',       page: 1, x: 380, y: 620, fontSize: 10 },
    { fieldId: 'nationality',          label: 'Nationality',             dataSource: 'client.nationality',    page: 1, x: 165, y: 592, fontSize: 10 },
    { fieldId: 'dob',                  label: 'Date of birth',           dataSource: 'client.dateOfBirth',    page: 1, x: 165, y: 564, fontSize: 10, dateFormat: 'DD/MM/YYYY' },
    { fieldId: 'passport_no',          label: 'Passport number',         dataSource: 'client.passportNumber', page: 1, x: 165, y: 536, fontSize: 10 },
    { fieldId: 'visa_type',            label: 'Current visa type',       dataSource: 'client.visaType',       page: 1, x: 350, y: 536, fontSize: 10 },
    { fieldId: 'current_address',      label: 'Address in Thailand',     dataSource: 'client.address',        page: 1, x: 165, y: 480, fontSize: 10 },
    { fieldId: 'job_title',            label: 'Position / Job title',    dataSource: 'matter.subType',        page: 1, x: 165, y: 424, fontSize: 10, maxLength: 50 },
  ],
}

const WP10: StockFormDefinition = {
  stockId: 'th-doe-wp10',
  name: 'WP.10 — Notification of Change of Employer / Work Type',
  nameLocal: 'แบบแจ้งการเปลี่ยนนายจ้างหรือประเภทงาน',
  description: 'Filed when a work permit holder changes employer or type of permitted work. Must be filed within 15 days of the change.',
  practiceArea: 'immigration',
  sourceUrl: 'https://www.doe.go.th/prd/assets/upload/files/alien_th/wp_10.pdf',
  fillMode: 'coordinate',
  needsCalibration: true,
  fields: [
    { fieldId: 'firstname',        label: 'First name',          dataSource: 'client.firstName',       page: 1, x: 165, y: 640, fontSize: 10 },
    { fieldId: 'lastname',         label: 'Last name',           dataSource: 'client.lastName',        page: 1, x: 380, y: 640, fontSize: 10 },
    { fieldId: 'nationality',      label: 'Nationality',         dataSource: 'client.nationality',     page: 1, x: 165, y: 612, fontSize: 10 },
    { fieldId: 'passport_no',      label: 'Passport number',     dataSource: 'client.passportNumber',  page: 1, x: 165, y: 584, fontSize: 10 },
    { fieldId: 'permit_number',    label: 'Work permit number',  dataSource: 'client.visaNumber',      page: 1, x: 165, y: 556, fontSize: 10 },
    { fieldId: 'current_address',  label: 'Address',             dataSource: 'client.address',         page: 1, x: 165, y: 500, fontSize: 10 },
  ],
}

// ─────────────────────────────────────────────────────────────────────────────
// CORPORATE / DBD FORMS — กรมพัฒนาธุรกิจการค้า (Department of Business Development)
// ─────────────────────────────────────────────────────────────────────────────

const DBD_AFFIDAVIT: StockFormDefinition = {
  stockId: 'th-dbd-company-affidavit',
  name: 'Company Affidavit Request — DBD Certified Extract',
  nameLocal: 'คำขอหนังสือรับรองบริษัทจากกรมพัฒนาธุรกิจการค้า',
  description: 'Request form for a certified company affidavit (หนังสือรับรอง) from the Department of Business Development. Used in contracts, opening bank accounts, and BOI applications.',
  practiceArea: 'corporate',
  sourceUrl: 'https://www.dbd.go.th/download/downloads/09_cd/form_request_information.pdf',
  fallbackUrls: [
    'https://www.dbd.go.th/download/PDF_law/form_request_information.pdf',
  ],
  fillMode: 'coordinate',
  needsCalibration: true,
  notes: 'DBD provides this form at their counters. The online version may differ. Corporate clients only.',
  fields: [
    { fieldId: 'company_name',     label: 'Company name (Thai)',   dataSource: 'client.companyName',        page: 1, x: 165, y: 640, fontSize: 10 },
    { fieldId: 'reg_number',       label: 'Registration number',   dataSource: 'client.registrationNumber', page: 1, x: 165, y: 612, fontSize: 10 },
    { fieldId: 'contact_name',     label: 'Contact person',        dataSource: 'static',                    page: 1, x: 165, y: 584, fontSize: 10, staticValue: '' },
  ],
}

const DBD_LIST_OF_SHAREHOLDERS: StockFormDefinition = {
  stockId: 'th-dbd-bor5',
  name: 'Bor.Or.Jor.5 — List of Shareholders',
  nameLocal: 'บอจ.5 — บัญชีรายชื่อผู้ถือหุ้น',
  description: 'Statutory list of shareholders filed annually with DBD or whenever share composition changes. Required for all Thai limited companies.',
  practiceArea: 'corporate',
  sourceUrl: 'https://www.dbd.go.th/download/downloads/03_boj/form_boj5.pdf',
  fallbackUrls: [
    'https://www.dbd.go.th/download/downloads/08_fn/form_send_shareholder.pdf',
  ],
  fillMode: 'coordinate',
  needsCalibration: true,
  fields: [
    { fieldId: 'company_name',  label: 'Company name',         dataSource: 'client.companyName',        page: 1, x: 165, y: 700, fontSize: 10 },
    { fieldId: 'reg_number',    label: 'Registration number',  dataSource: 'client.registrationNumber', page: 1, x: 165, y: 672, fontSize: 10 },
  ],
}

// ─────────────────────────────────────────────────────────────────────────────
// BOI FORMS — สำนักงานคณะกรรมการส่งเสริมการลงทุน (Board of Investment)
// ─────────────────────────────────────────────────────────────────────────────

const BOI_VISA_WP_REQUEST: StockFormDefinition = {
  stockId: 'th-boi-visa-wp-request',
  name: 'BOI Visa & Work Permit Recommendation Letter Request',
  nameLocal: 'คำขอหนังสือรับรองสิทธิ์ BOI สำหรับวีซ่าและใบอนุญาตทำงาน',
  description: 'Request for a BOI recommendation letter that enables the holder to obtain a Non-B visa and/or work permit under BOI promotion privileges. Filed through BOI One Stop Service.',
  practiceArea: 'corporate',
  sourceUrl: 'https://www.boi.go.th/upload/content/BOI_OSS_WorkPermit_2022_5ec31b4cdd4a4.pdf',
  fillMode: 'coordinate',
  needsCalibration: true,
  notes: 'Requires BOI project number (from BOI promotion certificate). Client must be corporate.',
  fields: [
    { fieldId: 'company_name',   label: 'Company name',          dataSource: 'client.companyName',        page: 1, x: 165, y: 650, fontSize: 10 },
    { fieldId: 'reg_number',     label: 'Company reg. number',   dataSource: 'client.registrationNumber', page: 1, x: 165, y: 622, fontSize: 10 },
    { fieldId: 'emp_firstname',  label: 'Employee first name',   dataSource: 'client.firstName',          page: 1, x: 165, y: 566, fontSize: 10 },
    { fieldId: 'emp_lastname',   label: 'Employee last name',    dataSource: 'client.lastName',           page: 1, x: 350, y: 566, fontSize: 10 },
    { fieldId: 'emp_passport',   label: 'Employee passport no.', dataSource: 'client.passportNumber',     page: 1, x: 165, y: 538, fontSize: 10 },
    { fieldId: 'emp_nationality',label: 'Employee nationality',  dataSource: 'client.nationality',        page: 1, x: 350, y: 538, fontSize: 10 },
  ],
}

// ─────────────────────────────────────────────────────────────────────────────
// REVENUE DEPARTMENT — กรมสรรพากร
// ─────────────────────────────────────────────────────────────────────────────

const PND91: StockFormDefinition = {
  stockId: 'th-rd-pnd91',
  name: 'P.N.D. 91 — Personal Income Tax Return (Foreign Individuals)',
  nameLocal: 'ภ.ง.ด.91 — แบบแสดงรายการภาษีเงินได้บุคคลธรรมดา',
  description: 'Annual personal income tax return for individuals with employment income only. Used by foreign employees filing Thai tax returns.',
  practiceArea: 'employment',
  sourceUrl: 'https://www.rd.go.th/publish/fileadmin/download/english/form/pnd91e.pdf',
  fillMode: 'coordinate',
  needsCalibration: true,
  notes: 'English version available. Financial figures must be entered manually. This form auto-fills personal identification fields only.',
  fields: [
    { fieldId: 'firstname',       label: 'First name',         dataSource: 'client.firstName',      page: 1, x: 165, y: 690, fontSize: 10 },
    { fieldId: 'lastname',        label: 'Last name',          dataSource: 'client.lastName',       page: 1, x: 380, y: 690, fontSize: 10 },
    { fieldId: 'nationality',     label: 'Nationality',        dataSource: 'client.nationality',    page: 1, x: 165, y: 662, fontSize: 10 },
    { fieldId: 'passport_no',     label: 'ID / Passport no.', dataSource: 'client.passportNumber', page: 1, x: 165, y: 634, fontSize: 10 },
    { fieldId: 'dob',             label: 'Date of birth',      dataSource: 'client.dateOfBirth',    page: 1, x: 350, y: 634, fontSize: 10, dateFormat: 'DD/MM/YYYY' },
    { fieldId: 'address',         label: 'Address in Thailand',dataSource: 'client.address',        page: 1, x: 165, y: 578, fontSize: 10 },
  ],
}

// ─────────────────────────────────────────────────────────────────────────────
// LAND DEPARTMENT — กรมที่ดิน
// ─────────────────────────────────────────────────────────────────────────────

const LAND_TRANSFER_REQUEST: StockFormDefinition = {
  stockId: 'th-land-transfer-request',
  name: 'Land Department — Transfer of Ownership Request',
  nameLocal: 'คำขอโอนกรรมสิทธิ์ที่ดิน',
  description: 'Buyer/seller identification form for property title transfer at the Land Department office. Filled in by the attending attorney or the parties.',
  practiceArea: 'property',
  sourceUrl: 'https://www.dol.go.th/dol/image/news/FileUpload/156_1557385278.pdf',
  fillMode: 'coordinate',
  needsCalibration: true,
  notes: 'Property details (chanote number, plot area, location) must be entered manually. This form auto-fills the client identification section.',
  fields: [
    { fieldId: 'party_firstname',  label: 'Party first name',     dataSource: 'client.firstName',      page: 1, x: 165, y: 660, fontSize: 10 },
    { fieldId: 'party_lastname',   label: 'Party last name',      dataSource: 'client.lastName',       page: 1, x: 380, y: 660, fontSize: 10 },
    { fieldId: 'id_number',        label: 'ID / Passport number', dataSource: 'client.passportNumber', page: 1, x: 165, y: 632, fontSize: 10 },
    { fieldId: 'nationality',      label: 'Nationality',          dataSource: 'client.nationality',    page: 1, x: 350, y: 632, fontSize: 10 },
    { fieldId: 'address',          label: 'Address',              dataSource: 'client.address',        page: 1, x: 165, y: 576, fontSize: 10 },
  ],
}

// ─────────────────────────────────────────────────────────────────────────────
// EXPORT
// ─────────────────────────────────────────────────────────────────────────────

export const STOCK_FORMS: StockFormDefinition[] = [
  // Immigration
  TM7,
  TM8,
  TM28,
  TM30,
  TM47,
  WP1,
  WP10,
  // Corporate / DBD
  DBD_AFFIDAVIT,
  DBD_LIST_OF_SHAREHOLDERS,
  // BOI
  BOI_VISA_WP_REQUEST,
  // Revenue
  PND91,
  // Property
  LAND_TRANSFER_REQUEST,
]
// Corporate Annual Compliance forms appended after declaration below

// ─────────────────────────────────────────────────────────────────────────────
// CORPORATE ANNUAL COMPLIANCE — บริษัทจำกัด (Thai Limited Company)
//
// HTML-template mode: complex bilingual EN/TH documents rendered to PDF
// via headless Chrome. No source PDF — the template IS the document.
//
// Data context: resolved from matter.annualCompliance.* by the annual
// compliance service before calling form-templates generate().
// ─────────────────────────────────────────────────────────────────────────────

export const CORPORATE_ANNUAL_COMPLIANCE_FORMS: StockFormDefinition[] = [
  {
    stockId: 'th-corp-bod-notice',
    name: 'BOD Notice — Notice of Board Meeting',
    nameLocal: 'หนังสือเชิญประชุมคณะกรรมการบริษัท',
    description: 'Formal notice calling the Board of Directors meeting to resolve calling the AGM. Bilingual EN/TH.',
    practiceArea: 'corporate',
    fillMode: 'html-template',
    needsCalibration: false,
    notes: 'Template resolved at generation time using annual compliance matter data.',
    fields: [
      { fieldId: 'companyNameEn',    label: 'Company Name (EN)',     dataSource: 'matter.annualCompliance.companyNameEn' },
      { fieldId: 'companyNameTh',    label: 'Company Name (TH)',     dataSource: 'matter.annualCompliance.companyNameTh' },
      { fieldId: 'bodDate',          label: 'BOD Meeting Date',      dataSource: 'matter.annualCompliance.bodDate' },
      { fieldId: 'bodTime',          label: 'BOD Meeting Time',      dataSource: 'matter.annualCompliance.bodTime' },
      { fieldId: 'bodVenue',         label: 'BOD Venue',             dataSource: 'matter.annualCompliance.bodVenue' },
      { fieldId: 'chairmanEn',       label: 'Chairman Name (EN)',    dataSource: 'matter.annualCompliance.chairmanEn' },
      { fieldId: 'chairmanTh',       label: 'Chairman Name (TH)',    dataSource: 'matter.annualCompliance.chairmanTh' },
      { fieldId: 'fiscalYear',       label: 'Fiscal Year (CE)',      dataSource: 'matter.annualCompliance.fiscalYear' },
      { fieldId: 'fiscalYearTh',     label: 'Fiscal Year (BE)',      dataSource: 'matter.annualCompliance.fiscalYearTh' },
    ],
  },
  {
    stockId: 'th-corp-bod-acknowledgment',
    name: 'BOD Acknowledgment — Per Director',
    nameLocal: 'ใบรับหนังสือเชิญประชุมคณะกรรมการ (รายบุคคล)',
    description: 'Individual acknowledgment of BOD notice — one per director. Generated as a set.',
    practiceArea: 'corporate',
    fillMode: 'html-template',
    needsCalibration: false,
    notes: 'Generated once per director. Use annual-compliance bulk-generate endpoint.',
    fields: [
      { fieldId: 'directorName_En', label: 'Director Name (EN)', dataSource: 'matter.annualCompliance.directorName_En' },
      { fieldId: 'directorName_Th', label: 'Director Name (TH)', dataSource: 'matter.annualCompliance.directorName_Th' },
    ],
  },
  {
    stockId: 'th-corp-bod-minutes',
    name: 'BOD Minutes — Minutes of Board Meeting',
    nameLocal: 'รายงานการประชุมคณะกรรมการบริษัท',
    description: 'Official minutes of the Board of Directors meeting. Bilingual EN/TH.',
    practiceArea: 'corporate',
    fillMode: 'html-template',
    needsCalibration: false,
    fields: [],
  },
  {
    stockId: 'th-corp-bod-attendance',
    name: 'BOD Attendance Sheet',
    nameLocal: 'ใบเซ็นชื่อเข้าร่วมประชุมคณะกรรมการ',
    description: 'Director signature sheet for the Board of Directors meeting.',
    practiceArea: 'corporate',
    fillMode: 'html-template',
    needsCalibration: false,
    fields: [],
  },
  {
    stockId: 'th-corp-agm-invitation',
    name: 'AGM Invitation Letter',
    nameLocal: 'หนังสือเชิญประชุมสามัญประจำปีผู้ถือหุ้น',
    description: 'Formal invitation to all shareholders for the Annual General Meeting. Bilingual EN/TH with all 6 statutory agenda items.',
    practiceArea: 'corporate',
    fillMode: 'html-template',
    needsCalibration: false,
    fields: [],
  },
  {
    stockId: 'th-corp-agm-receipt',
    name: 'AGM Invitation Receipt — Per Shareholder',
    nameLocal: 'ใบรับหนังสือเชิญประชุมสามัญประจำปี (รายบุคคล)',
    description: 'Shareholder acknowledgment of AGM invitation — one per shareholder.',
    practiceArea: 'corporate',
    fillMode: 'html-template',
    needsCalibration: false,
    notes: 'Generated once per shareholder. Use annual-compliance bulk-generate endpoint.',
    fields: [
      { fieldId: 'shName_En', label: 'Shareholder Name (EN)', dataSource: 'matter.annualCompliance.shName_En' },
      { fieldId: 'shName_Th', label: 'Shareholder Name (TH)', dataSource: 'matter.annualCompliance.shName_Th' },
      { fieldId: 'shShares',  label: 'Share Count',           dataSource: 'matter.annualCompliance.shShares' },
    ],
  },
  {
    stockId: 'th-corp-agm-proxy',
    name: 'AGM Proxy Form — Per Shareholder',
    nameLocal: 'หนังสือมอบฉันทะ (รายบุคคล)',
    description: 'Proxy authorisation form — one per shareholder. Bilingual EN/TH.',
    practiceArea: 'corporate',
    fillMode: 'html-template',
    needsCalibration: false,
    fields: [],
  },
  {
    stockId: 'th-corp-agm-attendance',
    name: 'AGM Attendance Sheet',
    nameLocal: 'ใบเซ็นชื่อเข้าร่วมประชุมสามัญประจำปี',
    description: 'Shareholder attendance and signature sheet for the AGM.',
    practiceArea: 'corporate',
    fillMode: 'html-template',
    needsCalibration: false,
    fields: [],
  },
  {
    stockId: 'th-corp-agm-minutes',
    name: 'AGM Minutes — Minutes of Annual General Meeting',
    nameLocal: 'รายงานการประชุมสามัญประจำปีผู้ถือหุ้น',
    description: 'Official minutes of the Annual General Meeting with all 6 statutory resolutions. Bilingual EN/TH.',
    practiceArea: 'corporate',
    fillMode: 'html-template',
    needsCalibration: false,
    fields: [],
  },
  {
    stockId: 'th-corp-agm-voting-sheet',
    name: 'AGM Voting Sheet — Per Shareholder',
    nameLocal: 'บัตรลงคะแนนเสียง (รายบุคคล)',
    description: 'Individual voting ballot for each AGM agenda item — one per shareholder.',
    practiceArea: 'corporate',
    fillMode: 'html-template',
    needsCalibration: false,
    fields: [],
  },
]

// Merge corporate annual compliance into the main STOCK_FORMS array
STOCK_FORMS.push(...CORPORATE_ANNUAL_COMPLIANCE_FORMS)

export const STOCK_FORM_COUNT = STOCK_FORMS.length
