// =============================================================================
// 🧑‍💼 EMPLOYEE V2 QUERIES
// =============================================================================
// GraphQL запросы для системы управления сотрудниками V2

import { gql } from '@apollo/client'

// =============================================================================
// 🔍 QUERIES
// =============================================================================

// Получение простого списка сотрудников для селекторов
export const GET_MY_EMPLOYEES_V2 = gql`
  query GetMyEmployeesV2 {
    employeesV2 {
      items {
        id
        personalInfo {
          firstName
          lastName
          fullName
          avatar
        }
        workInfo {
          position
          department
          status
        }
      }
      stats {
        total
        active
        vacation
        sick
        fired
        averageSalary
      }
    }
  }
`

// Получение списка сотрудников с фильтрацией и пагинацией
export const GET_EMPLOYEES_V2 = gql`
  query GetEmployeesV2($input: EmployeesFilterInput) {
    employeesV2(input: $input) {
      items {
        id
        personalInfo {
          firstName
          lastName
          middleName
          fullName
          birthDate
          avatar
        }
        contactInfo {
          phone
          email
          telegram
          whatsapp
          address
        }
        workInfo {
          position
          department
          hireDate
          salary
          status
        }
        organizationId
        metadata {
          createdAt
          updatedAt
        }
      }
      pagination {
        total
        page
        limit
        totalPages
      }
      stats {
        total
        active
        vacation
        sick
        fired
        averageSalary
      }
    }
  }
`

// Получение конкретного сотрудника
export const GET_EMPLOYEE_V2 = gql`
  query GetEmployeeV2($id: ID!) {
    employeeV2(id: $id) {
      id
      personalInfo {
        firstName
        lastName
        middleName
        fullName
        birthDate
        avatar
      }
      documentsInfo {
        passportPhoto
        passportSeries
        passportNumber
        passportIssued
        passportDate
      }
      contactInfo {
        phone
        email
        telegram
        whatsapp
        address
        emergencyContact
        emergencyPhone
      }
      workInfo {
        position
        department
        hireDate
        salary
        status
      }
      organizationId
      organization {
        id
        name
        fullName
        type
      }
      metadata {
        createdAt
        updatedAt
      }
    }
  }
`

// Получение табеля сотрудника
export const GET_EMPLOYEE_SCHEDULE_V2 = gql`
  query GetEmployeeScheduleV2($input: EmployeeScheduleInput!) {
    employeeScheduleV2(input: $input) {
      employee {
        id
        personalInfo {
          firstName
          lastName
          fullName
        }
        workInfo {
          position
          department
        }
      }
      year
      month
      records {
        id
        date
        status
        hoursWorked
        overtimeHours
        notes
        metadata {
          createdAt
          updatedAt
        }
      }
      summary {
        totalDays
        workDays
        weekendDays
        vacationDays
        sickDays
        absentDays
        totalHours
        overtimeHours
      }
    }
  }
`

// =============================================================================
// 🔧 MUTATIONS
// =============================================================================

// Создание сотрудника V2
export const CREATE_EMPLOYEE_V2 = gql`
  mutation CreateEmployeeV2($input: CreateEmployeeInputV2!) {
    createEmployeeV2(input: $input) {
      success
      message
      employee {
        id
        personalInfo {
          firstName
          lastName
          middleName
          fullName
          avatar
        }
        contactInfo {
          phone
          email
        }
        workInfo {
          position
          department
          hireDate
          status
        }
        metadata {
          createdAt
          updatedAt
        }
      }
      errors {
        field
        message
      }
    }
  }
`

// Обновление сотрудника V2
export const UPDATE_EMPLOYEE_V2 = gql`
  mutation UpdateEmployeeV2($id: ID!, $input: UpdateEmployeeInputV2!) {
    updateEmployeeV2(id: $id, input: $input) {
      success
      message
      employee {
        id
        personalInfo {
          firstName
          lastName
          middleName
          fullName
          avatar
        }
        documentsInfo {
          passportPhoto
          passportSeries
          passportNumber
          passportIssued
          passportDate
        }
        contactInfo {
          phone
          email
          telegram
          whatsapp
          address
          emergencyContact
          emergencyPhone
        }
        workInfo {
          position
          department
          hireDate
          salary
          status
        }
        metadata {
          createdAt
          updatedAt
        }
      }
      errors {
        field
        message
      }
    }
  }
`

// Удаление сотрудника V2
export const DELETE_EMPLOYEE_V2 = gql`
  mutation DeleteEmployeeV2($id: ID!) {
    deleteEmployeeV2(id: $id)
  }
`

// Обновление табеля V2
export const UPDATE_EMPLOYEE_SCHEDULE_V2 = gql`
  mutation UpdateEmployeeScheduleV2($input: UpdateScheduleInputV2!) {
    updateEmployeeScheduleV2(input: $input) {
      success
      message
      record {
        id
        date
        status
        hoursWorked
        overtimeHours
        notes
        metadata {
          createdAt
          updatedAt
        }
      }
    }
  }
`