require 'rails_helper'

RSpec.describe UserThemeSlot, type: :model do
  it 'accepts a theme slot for one user, base theme, and slot number' do
    slot = described_class.new(user: create(:user),
                               base_theme: 'light',
                               slot_no: 1,
                               tokens: { 'background' => '0 0% 100%' })

    expect(slot).to be_valid
  end

  it 'requires unique slot numbers per user and base theme' do
    user = create(:user)
    described_class.create!(user:,
                            base_theme: 'dark',
                            slot_no: 2,
                            tokens: { 'background' => '222.2 84% 4.9%' })

    duplicate = described_class.new(user:,
                                    base_theme: 'dark',
                                    slot_no: 2,
                                    tokens: { 'background' => '0 0% 100%' })

    expect(duplicate).not_to be_valid
    expect(duplicate.errors[:user_id]).to be_present
  end

  it 'validates base theme, slot number, and token object shape' do
    slot = described_class.new(user: create(:user),
                               base_theme: 'system',
                               slot_no: 4,
                               tokens: 'not-object')

    expect(slot).not_to be_valid
    expect(slot.errors[:base_theme]).to be_present
    expect(slot.errors[:slot_no]).to be_present
    expect(slot.errors[:tokens]).to be_present
  end
end
