import { Category, City } from '../types';
import { User } from '../types/auth';

export const checkPermission = (
    user: User,
    category: Category,
    action: 'create' | 'edit' | 'delete'
): boolean => {
  if (user.permissions.isAdmin) return true;
  return !!user.permissions.categories[category.name]?.[action];
};

export const checkCityAccess = (user: User, city: City): boolean => {
  if (user.permissions.isAdmin) return true;
  return user.permissions.cities.includes(city);
};

export const getDefaultPermissions = () => ({
  categories: {
    Film: { create: false, edit: false, delete: false },
    Theater: { create: false, edit: false, delete: false },
    Music: { create: false, edit: false, delete: false },
    Sports: { create: false, edit: false, delete: false },
    Art: { create: false, edit: false, delete: false },
    Legends: { create: false, edit: false, delete: false },
    Anniversaries: { create: false, edit: false, delete: false },
    Memory: { create: false, edit: false, delete: false }
  },
  cities: [],
  isAdmin: false
});