export interface EnquiryOption {
  id: string;
  code: string;
  label: string;
  value: string | null;
}

export interface EnquiryProjectPartyRecord {
  id: string;
  organizationId: string;
  enquiryId: string;
  customerId: string;
  role: string;
  roleCode: string;
  roleLabel: string | null;
  remark: string | null;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
}

export interface EnquiryProjectPartyListItem extends EnquiryProjectPartyRecord {
  customerName: string;
  customerCode: string;
}

export interface EnquiryBranchOption {
  id: string;
  code: string;
  name: string;
  value: string | null;
}

export interface EnquiryCustomerLookup {
  id: string;
  code: string;
  name: string;
  branchId: string | null;
}

export interface EnquiryContactLookup {
  id: string;
  customerId: string;
  name: string;
  email: string | null;
  mobile: string | null;
  isPrimary: boolean;
}

export interface EnquiryAssignableUserLookup {
  id: string;
  name: string;
  membershipRole: 'admin' | 'user';
  businessRole: string;
}

export type EnquiryPipelineStage = 'lead' | 'enquiry' | 'closed_won' | 'closed_lost';

export interface EnquiryRecord {
  id: string;
  organizationId: string;
  branchId: string | null;
  code: string;
  customerId: string;
  contactId: string | null;
  title: string;
  description: string | null;
  requirement: string | null;
  projectName: string | null;
  projectLocation: string | null;
  productType: string;
  status: string;
  priority: string;
  leadChannel: string | null;
  estimatedValue: number | null;
  chancePercent: number | null;
  expectedCloseDate: string | null;
  competitor: string | null;
  source: string | null;
  notes: string | null;
  isHotProject: boolean;
  isActive: boolean;
  pipelineStage: EnquiryPipelineStage;
  assignedToUserId: string | null;
  assignedToName: string | null;
  assignedAt: string | null;
  assignedBy: string | null;
  assignedByName: string | null;
  assignmentRemark: string | null;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  createdBy: string;
  updatedBy: string;
}

export interface EnquiryListItem extends EnquiryRecord {
  customerName: string;
  contactName: string | null;
  followupCount: number;
  quotationCount: number;
  nextFollowupDate: string | null;
  createdByName: string | null;
}

export interface EnquiryFollowupRecord {
  id: string;
  organizationId: string;
  enquiryId: string;
  followupDate: string;
  followupType: string;
  contactId: string | null;
  outcome: string | null;
  notes: string | null;
  nextFollowupDate: string | null;
  nextAction: string | null;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  createdBy: string;
  updatedBy: string;
}

export interface EnquiryActivityRecord {
  id: string;
  action: string;
  entityType: string;
  entityId: string;
  createdAt: string;
  userId: string;
  actorName: string | null;
}

export interface EnquiryReferenceData {
  branches: EnquiryBranchOption[];
  statuses: EnquiryOption[];
  productTypes: EnquiryOption[];
  priorities: EnquiryOption[];
  leadChannels: EnquiryOption[];
  followupTypes: EnquiryOption[];
  projectPartyRoles: EnquiryOption[];
  customers: EnquiryCustomerLookup[];
  contacts: EnquiryContactLookup[];
  assignableUsers: EnquiryAssignableUserLookup[];
}

export interface EnquiryFilters {
  page?: number;
  limit?: number;
  search?: string;
  pipelineStage?: EnquiryPipelineStage;
  status?: string;
  productType?: string;
  priority?: string;
  branch?: string;
  customer?: string;
  sort?: string;
}

export interface EnquiryListResponse {
  success: boolean;
  time: string;
  message: string;
  totalItems: number;
  offset: number;
  limit: number;
  items: EnquiryListItem[];
}

export interface EnquiryDetailResponse {
  success: boolean;
  time: string;
  message: string;
  enquiry: EnquiryRecord;
  activity: EnquiryActivityRecord[];
}

export interface EnquiryProjectPartiesResponse {
  success: boolean;
  time: string;
  message: string;
  items: EnquiryProjectPartyListItem[];
}

export interface EnquiryFollowupsResponse {
  success: boolean;
  time: string;
  message: string;
  items: EnquiryFollowupRecord[];
}

export interface EnquiryProjectPartyMutationPayload {
  customerId: string;
  role: string;
  remark?: string | null;
}

export interface EnquiryMutationPayload {
  customerId: string;
  contactId?: string | null;
  title: string;
  description?: string;
  requirement?: string;
  projectName?: string;
  projectLocation?: string;
  branchId?: string | null;
  productType: string;
  status: string;
  priority: string;
  leadChannel?: string | null;
  estimatedValue?: number | null;
  chancePercent?: number | null;
  expectedCloseDate?: string | null;
  competitor?: string;
  source?: string;
  isHotProject?: boolean;
  notes?: string;
  isActive?: boolean;
  projectParties?: EnquiryProjectPartyMutationPayload[];
}

export interface EnquiryFollowupMutationPayload {
  followupDate: string;
  followupType: string;
  contactId?: string | null;
  outcome?: string;
  notes?: string;
  nextFollowupDate?: string | null;
  nextAction?: string;
}

export interface EnquiryAssignmentMutationPayload {
  assignedToUserId: string;
  remark?: string;
}

export interface EnquiryCustomerRelationItem {
  id: string;
  code: string;
  title: string;
  status: string;
  productType: string;
  updatedAt: string;
}

export interface MutationSuccessResponse {
  success: boolean;
  message: string;
}
