import {UserId} from '@caj/configs/types';
import LangFormat from '@caj/lang/default';

type GroupId = string;

export enum chatType {
  User = 0,
  Group = 1,
}

export enum chatTags {
  GROUP = 0,
  FRIEND = 1,
  GOOD_FRIEND = 2,
}

interface tagUIType {
  name: string;
  background: string;
  textColor?: string;
}

interface tagUITypeFinal extends tagUIType {
  textColor: string;
}

const tagUI: {[key in chatTags]: tagUIType} = {
  [chatTags.GROUP]: {
    name: 'Group',
    background: '#37f',
  },
  [chatTags.FRIEND]: {
    name: 'Friend',
    background: 'lime.300',
    textColor: '#111',
  },
  [chatTags.GOOD_FRIEND]: {
    name: 'Good friend',
    background: 'lime.600',
  },
};

export function getTagUI(tagKey: chatTags, lang?: LangFormat): tagUITypeFinal {
  let tag = tagUI[tagKey];

  tag.textColor = tag.textColor || '#fff';

  if (lang !== undefined && lang.chat.tags.names[tagKey] !== undefined) {
    tag.name = lang.chat.tags.names[tagKey];
  }

  return tag as tagUITypeFinal;
}

export type chatId = UserId | GroupId;

export interface chatEntity {
  type: chatType;
  id: chatId;
  title?: string;
  unreadMessages: number;
  tags: chatTags[];
}