import { describe, it, expect } from 'vitest'
import { presentBrand } from './company.presenter'

const fullBrand = {
  id: 'brand_1',
  companyId: 'comp_1',
  displayName: 'Test Rentals',
  subdomain: 'test-rentals',
  logoUrl: 'https://example.com/logo.jpg',
  primaryColor: '#1A56DB',
  defaultLocale: 'en',
  defaultCurrency: 'MAD',
  amanpayMerchantId: 'merchant-abc',
  amanpaySecretKey: 'super-secret-key',
  paypalEmail: 'paypal@example.com',
  paypalMerchantId: 'paypal-merchant-xyz',
  isListedOnCarplace: true,
}

describe('presentBrand', () => {
  it('strips amanpaySecretKey from the response', () => {
    const result = presentBrand(fullBrand)
    expect(result).not.toHaveProperty('amanpaySecretKey')
  })

  it('strips amanpayMerchantId from the response', () => {
    const result = presentBrand(fullBrand)
    expect(result).not.toHaveProperty('amanpayMerchantId')
  })

  it('strips paypalEmail from the response', () => {
    const result = presentBrand(fullBrand)
    expect(result).not.toHaveProperty('paypalEmail')
  })

  it('strips paypalMerchantId from the response', () => {
    const result = presentBrand(fullBrand)
    expect(result).not.toHaveProperty('paypalMerchantId')
  })

  it('sets amanpayConfigured=true when both amanpay credentials are present', () => {
    const result = presentBrand(fullBrand)
    expect(result.amanpayConfigured).toBe(true)
  })

  it('sets amanpayConfigured=false when amanpaySecretKey is null', () => {
    const result = presentBrand({ ...fullBrand, amanpaySecretKey: null })
    expect(result.amanpayConfigured).toBe(false)
  })

  it('sets amanpayConfigured=false when amanpayMerchantId is null', () => {
    const result = presentBrand({ ...fullBrand, amanpayMerchantId: null })
    expect(result.amanpayConfigured).toBe(false)
  })

  it('sets amanpayConfigured=false when both amanpay fields are null', () => {
    const result = presentBrand({ ...fullBrand, amanpayMerchantId: null, amanpaySecretKey: null })
    expect(result.amanpayConfigured).toBe(false)
  })

  it('sets paypalConfigured=true when paypalEmail is set', () => {
    const result = presentBrand({ ...fullBrand, paypalMerchantId: null })
    expect(result.paypalConfigured).toBe(true)
  })

  it('sets paypalConfigured=true when paypalMerchantId is set', () => {
    const result = presentBrand({ ...fullBrand, paypalEmail: null })
    expect(result.paypalConfigured).toBe(true)
  })

  it('sets paypalConfigured=false when both paypal fields are null', () => {
    const result = presentBrand({ ...fullBrand, paypalEmail: null, paypalMerchantId: null })
    expect(result.paypalConfigured).toBe(false)
  })

  it('preserves all non-credential fields', () => {
    const result = presentBrand(fullBrand)
    expect(result).toMatchObject({
      id:                   'brand_1',
      companyId:            'comp_1',
      displayName:          'Test Rentals',
      subdomain:            'test-rentals',
      logoUrl:              'https://example.com/logo.jpg',
      primaryColor:         '#1A56DB',
      defaultLocale:        'en',
      defaultCurrency:      'MAD',
      isListedOnCarplace: true,
    })
  })

  it('returns null when brand is null', () => {
    expect(presentBrand(null)).toBeNull()
  })

  it('returns undefined when brand is undefined', () => {
    expect(presentBrand(undefined)).toBeUndefined()
  })
})
