<script>
import Swal from "sweetalert2";
import { authenticatedRequest } from "@/components/session/authenticatedRequest.vue";
import { ObjectsGlobal } from "@/components/session/token/SessionUser/Objects/ObjectsGlobal.vue";
import { SessionUser } from "@/components/session/token/SessionUser.vue";
import {ref} from "vue";

/**
 * The DepartmentTimeBookingsOpeningHours object
 */
export const DepartmentTimeBookingsOpeningHours = {
  meta: {
    title: "Tidsbookings åbningstider",
    icon: "fas fa-list",
    description: "Oversigt over afdelings tidsbookings åbningstider.",
    endpoint: "/department/timebookings/opening-hours",
    labels: {
      single: "åbningstid",
      multiple: "åbningstider"
    }
  },
  columns: {
    id: {
      label: "ID",
      type: "number",
      sortable: true,
      creation: {
        required: false
      }
    },
    department: {
      label: "Afdeling",
      type: "select",
      sortable: true,
      creation: {
        required: true
      },
      options: async () => {
        return SessionUser.objects.departments.get.all();
      }
    },
    monday_start: {
      label: "Mandag åbningstid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    monday_end: {
      label: "Mandag lukketid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    tuesday_start: {
      label: "Tirsdag åbningstid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    tuesday_end: {
      label: "Tirsdag lukketid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    wednesday_start: {
      label: "Onsdag åbningstid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    wednesday_end: {
      label: "Onsdag lukketid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    thursday_start: {
      label: "Torsdag åbningstid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    thursday_end: {
      label: "Torsdag lukketid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    friday_start: {
      label: "Fredag åbningstid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    friday_end: {
      label: "Fredag lukketid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    saturday_start: {
      label: "Lørdag åbningstid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    saturday_end: {
      label: "Lørdag lukketid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    sunday_start: {
      label: "Søndag åbningstid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    },
    sunday_end: {
      label: "Søndag lukketid",
      type: "time",
      sortable: true,
      creation: {
        required: false
      }
    }
  },
  add: async (department, monday_start = null, monday_end = null, tuesday_start = null, tuesday_end = null, wednesday_start = null, wednesday_end = null, thursday_start = null, thursday_end = null, friday_start = null, friday_end = null, saturday_start = null, saturday_end = null, sunday_start = null, sunday_end = null) => {
    return ObjectsGlobal.add.object(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        {
          department: parseInt(department),
          monday_start: monday_start,
          monday_end: monday_end,
          tuesday_start: tuesday_start,
          tuesday_end: tuesday_end,
          wednesday_start: wednesday_start,
          wednesday_end: wednesday_end,
          thursday_start: thursday_start,
          thursday_end: thursday_end,
          friday_start: friday_start,
          friday_end: friday_end,
          saturday_start: saturday_start,
          saturday_end: saturday_end,
          sunday_start: sunday_start,
          sunday_end: sunday_end,
        }
    );
  },
  set: {
    monday_start: async (id, monday_start) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "monday_start",
        monday_start
      )
    },
    monday_end: async (id, monday_end) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "monday_end",
        monday_end
      )
    },
    tuesday_start: async (id, tuesday_start) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "tuesday_start",
        tuesday_start
      )
    },
    tuesday_end: async (id, tuesday_end) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "tuesday_end",
        tuesday_end
      )
    },
    wednesday_start: async (id, wednesday_start) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "wednesday_start",
        wednesday_start
      )
    },
    wednesday_end: async (id, wednesday_end) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "wednesday_end",
        wednesday_end
      )
    },
    thursday_start: async (id, thursday_start) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "thursday_start",
        thursday_start
      )
    },
    thursday_end: async (id, thursday_end) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "thursday_end",
        thursday_end
      )
    },
    friday_start: async (id, friday_start) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "friday_start",
        friday_start
      )
    },
    friday_end: async (id, friday_end) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "friday_end",
        friday_end
      )
    },
    saturday_start: async (id, saturday_start) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "saturday_start",
        saturday_start
      )
    },
    saturday_end: async (id, saturday_end) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "saturday_end",
        saturday_end
      )
    },
    sunday_start: async (id, sunday_start) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "sunday_start",
        sunday_start
      )
    },
    sunday_end: async (id, sunday_end) => {
      return ObjectsGlobal.set.column(
        DepartmentTimeBookingsOpeningHours.meta.endpoint,
        id,
        "sunday_end",
        sunday_end
      )
    },
  },
  get: {
    all: async () => {
      return ObjectsGlobal.get.objects(DepartmentTimeBookingsOpeningHours.meta.endpoint);
    },
    single: async (id) => {
      return ObjectsGlobal.get.object(DepartmentTimeBookingsOpeningHours.meta.endpoint, id);
    }
  },
  delete: async (id) => {
    return ObjectsGlobal.delete.object(DepartmentTimeBookingsOpeningHours.meta.endpoint, id);
  },
  functions: {
    showDeleteObjectForm: (id, onAfterSubmit = null) => {
      return ObjectsGlobal.showDeleteObjectForm(DepartmentTimeBookingsOpeningHours, id, onAfterSubmit);
    },
  },
  /**
   * Show the create object form
   * @param onAfterSubmit
   * @param lockedValues
   * @returns {Promise<SweetAlertResult<Awaited<any>>>}
   */
  showCreateObjectForm: (onAfterSubmit = null, lockedValues = {}) => {
    return ObjectsGlobal.showCreateObjectForm(DepartmentTimeBookingsOpeningHours, onAfterSubmit, lockedValues);
  },
  /**
   * Show the edit object field form
   * @param id
   * @param column
   * @param value
   * @param onAfterSubmit
   * @returns {Promise<SweetAlertResult<Awaited<any>>>}
   */
  showEditObjectFieldForm: (id, column, value, onAfterSubmit = null) => {
    return ObjectsGlobal.showEditObjectFieldForm(
        DepartmentTimeBookingsOpeningHours,
        id,
        column,
        value,
        onAfterSubmit
    );
  }
};
</script>