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



    /**
     * The Branding object
     */
    export const Branding = {
      meta: {
        title: "Branding",
        icon: "fas fa-list",
        description: "Oversigt over branding",
        endpoint: "/branding",
        labels: {
          single: "branding",
          multiple: "brands",
        }
      },
      columns: {
        id: {
          label: "ID",
          type: "number",
          sortable: true,
          creation: {
            required: false
          }
        },
        name: {
          label: "Navn",
          type: "string",
          sortable: true,
          creation: {
            required: true
          },
        },
        description: {
          label: "Beskrivelse",
          type: "string",
          sortable: true,
          creation: {
            required: true
          },
        },
        cvr: {
          label: "CVR",
          type: "number",
          sortable: true,
          creation: {
            required: true
          },
        },
        address: {
          label: "Adresse",
          type: "string",
          sortable: true,
          creation: {
            required: false
          },
        },
        phone_country_code: {
          label: "Landekode",
          type: "number",
          sortable: true,
          creation: {
            required: false
          },
        },
        phone_number: {
          label: "Telefonnummer",
          type: "number",
          sortable: true,
          creation: {
            required: false
          },
        },
        email: {
          label: "Email",
          type: "string",
          sortable: true,
          creation: {
            required: false
          },
        },
        website: {
          label: "Hjemmeside",
          type: "string",
          sortable: true,
          creation: {
            required: false
          },
        },
        banner: {
          label: "Banner",
          type: "string",
          sortable: false,
          creation: {
            required: false
          },
        },
        logo: {
          label: "Logo",
          type: "string",
          sortable: false,
          creation: {
            required: false
          },
        },
        favicon: {
          label: "Favicon",
          type: "string",
          sortable: false,
          creation: {
            required: false
          },
        },
        signature: {
          label: "Signatur",
          type: "string",
          sortable: false,
          creation: {
            required: false
          },
        },
      },
      add: async (name, description, cvr) => {
        return ObjectsGlobal.add.object(
            Branding.meta.endpoint,
            {
              name: name,
              description: description,
              cvr: cvr
            }
        );
      },
      set: {
        name: async (id, name) => {
          return ObjectsGlobal.set.column(
              Branding.meta.endpoint,
              id,
              "name",
              name
          )
        },
        description: async (id, description) => {
          return ObjectsGlobal.set.column(
              Branding.meta.endpoint,
              id,
              "description",
              description
          )
        },
        cvr: async (id, cvr) => {
          return ObjectsGlobal.set.column(
              Branding.meta.endpoint,
              id,
              "cvr",
              parseInt(cvr)
          )
        },
        address: async (id, address) => {
          return ObjectsGlobal.set.column(
              Branding.meta.endpoint,
              id,
              "address",
              address
          )
        },
        phone_country_code: async (id, phone_country_code) => {
          return ObjectsGlobal.set.column(
              Branding.meta.endpoint,
              id,
              "phone_country_code",
              parseInt(phone_country_code)
          )
        },
        phone_number: async (id, phone_number) => {
          return ObjectsGlobal.set.column(
              Branding.meta.endpoint,
              id,
              "phone_number",
              parseInt(phone_number)
          )
        },
        email: async (id, email) => {
          return ObjectsGlobal.set.column(
              Branding.meta.endpoint,
              id,
              "email",
              email
          )
        },
        website: async (id, website) => {
          return ObjectsGlobal.set.column(
              Branding.meta.endpoint,
              id,
              "website",
              website
          )
        },
        banner: async (id, banner) => {
          return ObjectsGlobal.set.column(
              Branding.meta.endpoint,
              id,
              "banner",
              banner
          )
        },
        logo: async (id, logo) => {
          return ObjectsGlobal.set.column(
              Branding.meta.endpoint,
              id,
              "logo",
              logo
          )
        },
        favicon: async (id, favicon) => {
          return ObjectsGlobal.set.column(
              Branding.meta.endpoint,
              id,
              "favicon",
              favicon
          )
        },
        signature: async (id, signature) => {
          return ObjectsGlobal.set.column(
              Branding.meta.endpoint,
              id,
              "signature",
              signature
          )
        },
      },
      get: {
        all: async () => {
          return ObjectsGlobal.get.objects(Branding.meta.endpoint);
        },
        single: async (id) => {
          return ObjectsGlobal.get.object(Branding.meta.endpoint, parseInt(id));
        }
      },
      delete: async (id) => {
        return ObjectsGlobal.delete.object(Branding.meta.endpoint, parseInt(id));
      },
      functions: {
      },
      /**
       * Show the create object form
       * @param onAfterSubmit
       * @returns {Promise<SweetAlertResult<Awaited<any>>>}
       */
      showCreateObjectForm: (onAfterSubmit = null) => {
        return ObjectsGlobal.showCreateObjectForm(Branding, onAfterSubmit);
      },
      /**
       * 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(
            Branding,
            id,
            column,
            value,
            onAfterSubmit
        );
      }
    };
</script>