import {
  type Meta,
  type StoryObj,
  applicationConfig,
  argsToTemplate,
  moduleMetadata,
} from '@storybook/angular';

import { StockInfoComponent } from '@isa/checkout/shared/product-info';
import { RemissionStockService } from '@isa/remission/data-access';
import { StockInfoDTO } from '@generated/swagger/inventory-api';

const meta: Meta<StockInfoComponent> = {
  title: 'checkout/shared/product-info/StockInfoComponent',
  component: StockInfoComponent,
  decorators: [
    applicationConfig({
      providers: [],
    }),
    moduleMetadata({
      imports: [],
      providers: [
        {
          provide: RemissionStockService,
          useValue: {
            fetchStock: async (
              params: { itemIds: number[]; assignedStockId?: number },
              abortSignal?: AbortSignal,
            ) => {
              const result: StockInfoDTO = {
                itemId: params.itemIds[0],
                stockId: params.assignedStockId,
                inStock: 14,
              };
              await new Promise((resolve) => setTimeout(resolve, 1000));
              return [result];
            },
          },
        },
      ],
    }),
  ],
};

export default meta;

type Story = StoryObj<StockInfoComponent>;

export const Primary: Story = {
  args: {
    item: {
      id: 123456,
      catalogAvailability: {
        ssc: '999',
        sscText: 'Lieferbar in 1-3 Werktagen',
      },
    },
  },
};
