import type { CrossParent } from "@/lib/api/types.gen";

export const NONE_SELECT_VALUE = "__none__";

export interface SelectOption {
  value: string;
  label: string;
}

export interface CrossingProjectRecord {
  id: string;
  crossingProjectDbId: string;
  crossingProjectName: string | null;
  name: string | null;
  crossingProjectDescription: string | null;
  description: string | null;
  programDbId: string | null;
  program_id: string | null;
  programName: string | null;
  program_name: string | null;
}

export interface PlannedCrossRecord {
  id: string;
  plannedCrossDbId: string;
  plannedCrossName: string | null;
  name: string | null;
  crossType: string | null;
  cross_type: string | null;
  status: string | null;
  crossingProjectDbId: string | null;
  crossing_project_id: string | null;
  crossingProjectName: string | null;
  crossing_project_name: string | null;
  planned: true;
  parent1: CrossParent | null;
  parent2: CrossParent | null;
}

export interface CrossPollinationEventRecord {
  id: string;
  pollination_number: string | null;
  pollination_successful: boolean | null;
  pollination_time_stamp: string | null;
}

export interface CrossRecord {
  id: string;
  crossDbId: string;
  crossName: string | null;
  name: string | null;
  crossType: string | null;
  cross_type: string | null;
  crossingProjectDbId: string | null;
  crossing_project_id: string | null;
  crossingProjectName: string | null;
  crossing_project_name: string | null;
  plannedCrossDbId: string | null;
  planned_cross_id: string | null;
  plannedCrossName: string | null;
  planned: false;
  parent1: CrossParent | null;
  parent2: CrossParent | null;
  pollination_events: CrossPollinationEventRecord[];
}

export interface CrossingProjectQuery {
  keyword?: string;
  program_id?: string;
}

export interface CrossingProjectDetail extends CrossingProjectRecord {
  plannedCrosses: PlannedCrossRecord[];
  actualCrosses: CrossRecord[];
  pedigreeNodes: PedigreeRecord[];
}

export interface CrossParentRow {
  id: string;
  cross_id: string;
  cross_name: string | null;
  planned: boolean;
  parent_slot: "parent1" | "parent2";
  parent_type: string | null;
  germplasm_id: string | null;
  germplasm_name: string | null;
  observation_unit_id: string | null;
  observation_unit_name: string | null;
  crossing_project_id: string | null;
  crossing_project_name: string | null;
}

export interface CrossParentFormState {
  cross_id: string;
  planned: boolean;
  crossing_project_id: string | null;
  crossing_project_name: string | null;
  parent1_type: string;
  parent1_germplasm_id: string;
  parent1_observation_unit_id: string;
  parent2_type: string;
  parent2_germplasm_id: string;
  parent2_observation_unit_id: string;
}

export interface PedigreeNodeParentRef {
  germplasmDbId?: string;
  germplasmName?: string;
  parentType?: string;
}

export interface PedigreeNodeSiblingRef {
  germplasmDbId?: string;
  germplasmName?: string;
}

export interface PedigreeRecord {
  id: string;
  pedigreeNodeDbId?: string;
  germplasmDbId: string | null;
  germplasm_id: string | null;
  germplasmName: string | null;
  germplasm_name: string | null;
  crossingProjectDbId: string | null;
  crossing_project_id: string | null;
  crossingProjectName: string | null;
  crossing_project_name: string | null;
  crossingYear: number | null;
  crossing_year: number | null;
  familyCode: string | null;
  family_code: string | null;
  pedigreeString: string | null;
  pedigree_string: string | null;
  parents?: PedigreeNodeParentRef[];
  siblings?: PedigreeNodeSiblingRef[];
}

export type PedigreeEdgeType = "parent" | "child" | "sibling";

export interface PedigreeEdgeRow {
  id: string;
  edge_type: PedigreeEdgeType;
  parent_type: string | null;
  this_node_id: string;
  this_node_name: string | null;
  connected_node_id: string;
  connected_node_name: string | null;
  read_only?: boolean;
}

export interface PedigreeEdgeFormState {
  edge_type: string;
  parent_type: string;
  this_node_id: string;
  connected_node_id: string;
}
