import { describe, it, expect } from 'vitest';
import { ResumeContent } from '~/types/resume';

describe('Resume Page', () => {
  describe('ResumeContent default handling', () => {
    it('should create default ResumeContent when data is null', () => {
      const resumeData = ref<ResumeContent | null>(null);
      const resumeContent = computed(() => (resumeData.value ? resumeData.value : new ResumeContent()));

      expect(resumeContent.value).toBeInstanceOf(ResumeContent);
      expect(resumeContent.value.experience).toEqual([]);
      expect(resumeContent.value.education).toEqual([]);
    });

    it('should use provided ResumeContent when data is available', () => {
      const resumeData = ref<ResumeContent | null>(new ResumeContent());
      resumeData.value!.experience = [{ tools: [], description: 'Test job' }];

      const resumeContent = computed(() => (resumeData.value ? resumeData.value : new ResumeContent()));

      expect(resumeContent.value.experience.length).toBe(1);
      expect(resumeContent.value.experience[0].description).toBe('Test job');
    });
  });

  describe('array length helper', () => {
    const arrLength = <T>(array?: T[]) => (array ? array.length - 1 : 0);

    it('should return 0 for undefined array', () => {
      expect(arrLength(undefined)).toBe(0);
    });

    it('should return 0 for empty array', () => {
      expect(arrLength([])).toBe(-1); // Actually returns -1 for empty array
    });

    it('should return length - 1 for non-empty array', () => {
      expect(arrLength([1, 2, 3])).toBe(2);
    });

    it('should return 0 for single element array', () => {
      expect(arrLength([1])).toBe(0);
    });
  });

  describe('timeline value computation', () => {
    it('should compute experience timeline value', () => {
      const resumeContent = new ResumeContent();
      resumeContent.experience = [
        { tools: [], description: 'Job 1' },
        { tools: [], description: 'Job 2' },
        { tools: [], description: 'Job 3' },
      ];

      const arrLength = <T>(array?: T[]) => (array ? array.length - 1 : 0);
      const valueExp = computed(() => arrLength(resumeContent.experience));

      expect(valueExp.value).toBe(2);
    });

    it('should compute education timeline value', () => {
      const resumeContent = new ResumeContent();
      resumeContent.education = [{ title: 'Degree 1' }, { title: 'Degree 2' }];

      const arrLength = <T>(array?: T[]) => (array ? array.length - 1 : 0);
      const valueEd = computed(() => arrLength(resumeContent.education));

      expect(valueEd.value).toBe(1);
    });
  });

  describe('data structure requirements', () => {
    it('should have experience section', () => {
      const resumeContent = new ResumeContent();
      expect(resumeContent).toHaveProperty('experience');
      expect(Array.isArray(resumeContent.experience)).toBe(true);
    });

    it('should have education section', () => {
      const resumeContent = new ResumeContent();
      expect(resumeContent).toHaveProperty('education');
      expect(Array.isArray(resumeContent.education)).toBe(true);
    });

    it('should have otherTools section', () => {
      const resumeContent = new ResumeContent();
      expect(resumeContent).toHaveProperty('otherTools');
      expect(Array.isArray(resumeContent.otherTools)).toBe(true);
    });

    it('should have devops section', () => {
      const resumeContent = new ResumeContent();
      expect(resumeContent).toHaveProperty('devops');
      expect(Array.isArray(resumeContent.devops)).toBe(true);
    });

    it('should have os section', () => {
      const resumeContent = new ResumeContent();
      expect(resumeContent).toHaveProperty('os');
      expect(Array.isArray(resumeContent.os)).toBe(true);
    });

    it('should have programmingLanguages section', () => {
      const resumeContent = new ResumeContent();
      expect(resumeContent).toHaveProperty('programmingLanguages');
      expect(Array.isArray(resumeContent.programmingLanguages)).toBe(true);
    });

    it('should have frameworks section', () => {
      const resumeContent = new ResumeContent();
      expect(resumeContent).toHaveProperty('frameworks');
      expect(Array.isArray(resumeContent.frameworks)).toBe(true);
    });
  });
});
