import { describe, it, expect } from 'vitest';
import { CreatePriceRecordSchema, BulkPriceRecordInputSchema } from './price-record.schemas.js';
import { ServingUnit } from '../enums/product.enums.js';

describe('PriceRecord Schemas', () => {
  describe('CreatePriceRecordSchema', () => {
    it('should validate a valid payload', () => {
      const payload = {
        productId: 'prod-1',
        storeId: 'store-1',
        price: 4.99,
        currency: 'USD',
        quantity: 500,
        unit: ServingUnit.GRAMS,
        notes: 'On sale',
      };
      const result = CreatePriceRecordSchema.safeParse(payload);
      expect(result.success).toBe(true);
    });

    it('should reject negative prices', () => {
      const payload = {
        productId: 'prod-1',
        storeId: 'store-1',
        price: -1.5,
        quantity: 500,
        unit: ServingUnit.GRAMS,
      };
      const result = CreatePriceRecordSchema.safeParse(payload);
      expect(result.success).toBe(false);
    });
  });

  describe('BulkPriceRecordInputSchema', () => {
    it('should validate valid bulk inputs', () => {
      const payload = {
        storeId: 'store-2',
        items: [
          { productId: 'p1', price: 2.5, quantity: 1, unit: ServingUnit.PIECES },
          { productId: 'p2', price: 3.0, quantity: 100, unit: ServingUnit.MILLILITERS },
        ],
      };
      const result = BulkPriceRecordInputSchema.safeParse(payload);
      expect(result.success).toBe(true);
    });

    it('should require at least one item', () => {
      const payload = {
        storeId: 'store-2',
        items: [],
      };
      const result = BulkPriceRecordInputSchema.safeParse(payload);
      expect(result.success).toBe(false);
    });
  });
});
