import { describe, expect, it } from 'vitest'
import {
  isMarketplaceProviderError,
  isMarketplaceWireError,
  isVendorNotFoundError,
  isVendorProductNotFoundError,
  isVendorAuthorizationError,
  isVendorStateError,
  isCommissionRateError,
  isVendorAlreadyExistsError,
} from './errors.js'

describe('isMarketplaceProviderError', () => {
  it('matches by structural name tag', () => {
    expect(isMarketplaceProviderError({ name: 'MarketplaceProviderError' })).toBe(true)
    expect(isMarketplaceProviderError({ name: 'Other' })).toBe(false)
    expect(isMarketplaceProviderError(null)).toBe(false)
    expect(isMarketplaceProviderError('string')).toBe(false)
  })
})

describe('isMarketplaceWireError', () => {
  it('matches by structural name tag', () => {
    expect(isMarketplaceWireError({ name: 'MarketplaceWireError' })).toBe(true)
    expect(isMarketplaceWireError({ name: 'Other' })).toBe(false)
    expect(isMarketplaceWireError(null)).toBe(false)
  })
})

describe('isVendorNotFoundError', () => {
  it('matches by name and code', () => {
    expect(isVendorNotFoundError({ name: 'VendorNotFoundError', code: 'VENDOR_NOT_FOUND' })).toBe(true)
    expect(isVendorNotFoundError({ name: 'Other', code: 'VENDOR_NOT_FOUND' })).toBe(false)
  })
})

describe('isVendorProductNotFoundError', () => {
  it('matches by name and code', () => {
    expect(
      isVendorProductNotFoundError({ name: 'VendorProductNotFoundError', code: 'VENDOR_PRODUCT_NOT_FOUND' }),
    ).toBe(true)
    expect(isVendorProductNotFoundError({ name: 'Other', code: 'VENDOR_PRODUCT_NOT_FOUND' })).toBe(false)
  })
})

describe('isVendorAuthorizationError', () => {
  it('matches by name and code', () => {
    expect(isVendorAuthorizationError({ name: 'VendorAuthorizationError', code: 'VENDOR_FORBIDDEN' })).toBe(true)
    expect(isVendorAuthorizationError({ name: 'Other', code: 'VENDOR_FORBIDDEN' })).toBe(false)
  })
})

describe('isVendorStateError', () => {
  it('matches by name and code', () => {
    expect(isVendorStateError({ name: 'VendorStateError', code: 'VENDOR_STATE' })).toBe(true)
    expect(isVendorStateError({ name: 'Other', code: 'VENDOR_STATE' })).toBe(false)
  })
})

describe('isCommissionRateError', () => {
  it('matches by name and code', () => {
    expect(isCommissionRateError({ name: 'CommissionRateError', code: 'COMMISSION_RATE_INVALID' })).toBe(true)
    expect(isCommissionRateError({ name: 'Other', code: 'COMMISSION_RATE_INVALID' })).toBe(false)
  })
})

describe('isVendorAlreadyExistsError', () => {
  it('matches by name and code', () => {
    expect(isVendorAlreadyExistsError({ name: 'VendorAlreadyExistsError', code: 'VENDOR_ALREADY_EXISTS' })).toBe(true)
    expect(isVendorAlreadyExistsError({ name: 'Other', code: 'VENDOR_ALREADY_EXISTS' })).toBe(false)
  })
})
