import {
  BaseFields,
  Customer,
  Employee,
  Location,
  MeetingType,
  Outcome,
  Subject,
  WithContactEmployee,
  WithEmployeeUser,
} from ".";

export type AppointmentState =
  | "incoming"
  | "outgoing"
  | "completed"
  | "cancelled"
  | "accepted"
  | "occurred";

export enum AppointmentStateEnum {
  ACCEPTED = "accepted",
  INCOMING = "incoming",
  OUTGOING = "outgoing",
  COMPLETED = "completed",
  CANCELLED = "cancelled",
  OCCURRED = "occurred",
}

export enum AppointmentUserType {
  CUSTOMER = "customer",
  EMPLOYEE = "employee",
}

export enum ApplicationType {
  WEB_APP = "Skedify_Web_Application",
  PLUGIN = "Skedify_Plugin",
  PBA_BOOKING = "Skedify_PBA_booking",
  PBA_SELF_SERVICE = "Skedify_PBA_selfservice",
}

export interface AppointmentMessage {
  category:
    | "dateChangedByContact"
    | "assignedByContact"
    | "possibilitiesRequestedByContact"
    | "cancelledByContact"
    | "acceptedByContact";
  created_by_id: string;
  created_by_type: "employee" | "customer";
  value: string;
}

export interface Appointment extends Omit<BaseFields, "enterprise_id"> {
  uuid: string;
  listing_uuid: string | null;
  contact_id: string;
  customer_id: string;
  subject_id: string;
  office_id: string;
  external_id: string | null;
  state: AppointmentState;
  meeting_type: MeetingType;
  first_possibility_id: string | null;
  notes: string | null;
  outcome_remark: string | null;
  trailing_buffer_time: number;
  metadata: any[];
  location: Location | null;
  customer_showed: boolean;
  is_success: boolean;
  video_url_for_contact: string | null;
  video_url_for_customer: string | null;
  video_test_url_for_contact: string | null;
  video_test_url_for_customer: string | null;
  cancellation_reason_id: string | null;
  cancelled_by_id: string | null;
  cancelled_by_type: AppointmentUserType | null;
  initiated_from: ApplicationType | null;
  initiated_by_id: string;
  initiated_by_type: AppointmentUserType;
  updated_at: string;
  updated_by_id: string | null;
  updated_by_type: AppointmentUserType | null;
}

export interface AppointmentOutcome {
  id: string;
  appointment_id: string;
  outcome_id: string;
}

export interface Possibility extends Omit<BaseFields, "enterprise_id" | "external_id"> {
  appointment_id: string;
  start: string;
  end: string;
  timezone: string;
  duration: number;
  is_accepted: boolean;
  next_possibility_id: string | null;
  created_by_id: string;
  created_by_type: AppointmentUserType;
  updated_by_id: string | null;
  updated_by_type: AppointmentUserType | null;
  updated_at: string;
}

export interface AppointmentAnswer {
  id: string;
  value: string | number | string[] | null;
  appointment_id: string;
  question_id: string;
  option_id: string | null;
}

export interface WithAnswers {
  answers: AppointmentAnswer[];
}

export interface WithSubject {
  subject: Subject;
}

export interface WithCustomer {
  customer: Customer;
}

export interface WithContact {
  contact: Employee & WithEmployeeUser & WithContactEmployee;
}

export interface WithAcceptedPossibility {
  accepted_possibility: Possibility;
}

export interface WithPossibilities {
  possibilities: Possibility[];
}

export interface WithCalendarLinks {
  calendar_links: {
    google: string;
    yahoo: string;
    outlook: string;
    ical: string;
  };
}

export type WithOutcomes = {
  outcomes: Outcome[];
};
