import { rest } from 'msw';
import { setupServer } from 'msw/node';
import 'whatwg-fetch';

import config from '../../config/app';
const API_ENDPOINT = config.development.api_endpoint;

export const server = setupServer(  
    rest.options('*', (req, res, ctx) =>
      res(
        ctx.status(200),
        ctx.set('access-control-allow-origin', '*'),
        ctx.set('Access-Control-Allow-Headers', 'x-cap-org'),
        ctx.set('Access-Control-Allow-Headers', 'x-cap-remote-user'),
        ctx.set('Access-Control-Allow-Headers', 'x-cap-api-data-context-org-id'),
        ctx.set('Access-Control-Allow-Headers', 'x-cap-api-auth-org-id'),
      ),
    ),
  );

export const getS3FileSizesFromUrlSuccessResponse = rest.post(
    `${API_ENDPOINT}/assets/files/metadata`,
    (req, res, ctx) =>
      res(
        ctx.status(200),
        ctx.json({
            "success": true,
            "status": {
                "isError": false,
                "code": 200,
                "message": "success"
            },
            "message": "Meta data fecthed successfully",
            "response": {
                "123.jpg": 400,
                "456.jpg": 500,
            }
        }),
      ),
  );

  export const getS3FileSizesFromUrlSuccessResponse2 = rest.post(
    `${API_ENDPOINT}/assets/files/metadata`,
    (req, res, ctx) =>
      res(
        ctx.status(200),
        ctx.json({
            "success": true,
            "status": {
                "isError": false,
                "code": 200,
                "message": "success"
            },
            "message": "Meta data fecthed successfully",
            "response": {
                "f98ce0c0-53f8-4fbd-b4e3-05953dda.jpg": 102400, // 102400 bytes, should map to quality=60 due to bug in getS3EmailImageQualityMapping
            }
        }),
      ),
  );

  export const getS3FileSizesFromUrlFailureResponse = rest.post(
    `${API_ENDPOINT}/assets/files/metadata`,
    (req, res, ctx) =>
      res(
        ctx.status(500),
        ctx.json({
            "success": false,
            "status": {
                "isError": true,
                "code": 500,
                "message": "cannot fetch data"
            },
            "message": "cannot fetch data",
        }),
      ),
  );