import AbstractMenuBuilder from '~/services/layout/menuBuilder/abstractMenuBuilder'
import {MenuItems, MenuGroup, MenuItem} from "~/types/layout";
import {MENU_LINK_TYPE} from "~/types/enum/layout";

/**
 * Menu Cotisation (CMF)
 */
export default class CotisationsMenuBuilder extends AbstractMenuBuilder {
  static readonly menuName = "Cotisation"

  /**
   * Construit le menu Cotisations ou null si aucune page accessible
   */
  build (): MenuItem | MenuGroup | null {
    const children: MenuItems = []

    if (this.ability.can('display', 'rate_cotisation_page')) {
      children.push(this.createItem('rate_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/rate', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'parameters_cotisation_page')) {
      children.push(this.createItem('parameters_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/parameter', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'send_cotisation_page')) {
      children.push(this.createItem('send_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/send', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'state_cotisation_page')) {
      children.push(this.createItem('state_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/state', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'pay_cotisation_page')) {
      children.push(this.createItem('pay_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/pay', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'check_cotisation_page')) {
      children.push(this.createItem('check_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/check', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'ledger_cotisation_page')) {
      children.push(this.createItem('ledger_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/ledger', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'magazine_cotisation_page')) {
      children.push(this.createItem('magazine_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/magazine', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'ventilated_cotisation_page')) {
      children.push(this.createItem('ventilated_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/ventilated', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'pay_erase_cotisation_page')) {
      children.push(this.createItem('pay_erase_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/payerase', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'resume_cotisation_page')) {
      children.push(this.createItem('resume_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/resume', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'history_cotisation_page')) {
      children.push(this.createItem('history_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/history', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'call_cotisation_page')) {
      children.push(this.createItem('call_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/call', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'history_structure_cotisation_page')) {
      children.push(this.createItem('history_structure_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/historystructure', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'insurance_cotisation_page')) {
      children.push(this.createItem('insurance_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/insurance', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'resume_all_cotisation_page')) {
      children.push(this.createItem('resume_all_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/resumeall', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'resume_pay_cotisation_page')) {
      children.push(this.createItem('resume_pay_cotisation', {name: 'fas fa-euro-sign'}, '/cotisation/resumepay', MENU_LINK_TYPE.V1))
    }

    if (children.length > 1) {
      // Plusieurs éléments, on retourne un groupe
      return this.createGroup('cotisations', {name: 'fas fa-money-bill'}, children)
    }
    else if (children.length === 1) {
      // Un seul élément, on retourne cet élément seul
      return children[0]
    }

    return null
  }
}
