import type { WashingPlaceRecord } from "@/types/master-data";

type SerializableWashingPlace = {
  id: bigint;
  code: string;
  name: string;
  address: string | null;
  phone: string | null;
  website: string | null;
  email: string | null;
  status: string;
  createdAt: Date;
  updatedAt: Date;
  contactPeople?: Array<{
    id: bigint;
    name: string;
    mobilePhone: string | null;
    email: string | null;
  }>;
};

export function serializeWashingPlace(place: SerializableWashingPlace): WashingPlaceRecord {
  return {
    id: place.id.toString(),
    code: place.code,
    name: place.name,
    address: place.address,
    phone: place.phone,
    website: place.website,
    email: place.email,
    contact_people: (place.contactPeople ?? []).map((contact) => ({
      id: contact.id.toString(),
      name: contact.name,
      mobile_phone: contact.mobilePhone,
      email: contact.email
    })),
    status: place.status,
    created_at: place.createdAt.toISOString(),
    updated_at: place.updatedAt.toISOString()
  };
}
