import { describe, it, expect, vi, beforeEach } from 'vitest';
import { projectService } from './projectService';

describe('projectService', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  describe('list', () => {
    it('should return list of projects', async () => {
      const result = await projectService.list();

      expect(result).toBeDefined();
      expect(result).toHaveProperty('projects');
      expect(Array.isArray(result.projects)).toBe(true);
      expect(result.projects.length).toBeGreaterThan(0);
      expect(result.projects[0]).toHaveProperty('id');
      expect(result.projects[0]).toHaveProperty('name');
      expect(result.projects[0]).toHaveProperty('daw');
    });
  });

  describe('get', () => {
    it('should return project details', async () => {
      const result = await projectService.get('p1');

      expect(result).toBeDefined();
      expect(result).toHaveProperty('project');
      expect(result.project).toHaveProperty('id');
      expect(result.project).toHaveProperty('name');
    });
  });

  describe('create', () => {
    it('should create a new project', async () => {
      const newProject = await projectService.create({
        name: 'Test Project',
        daw: 'Ableton',
        bpm: 128,
      });

      expect(newProject).toBeDefined();
      expect(newProject).toHaveProperty('id');
      expect(newProject.name).toBe('Test Project');
    });
  });

  describe('update', () => {
    it('should update a project', async () => {
      const updated = await projectService.update('p1', {
        name: 'Updated Name',
      });

      expect(updated).toBeDefined();
      expect(updated).toHaveProperty('id');
      expect(updated.name).toBe('Updated Name');
    });
  });

  describe('delete', () => {
    it('should delete a project', async () => {
      const result = await projectService.delete('p1');

      expect(result).toBeDefined();
      expect(result.success).toBe(true);
    });
  });
});
