package queries

const GetCostingFirstGroupMailMappingRows = `
SELECT
  f.urun_ilk_grubu,
  m.id::text,
  m.email,
  COALESCE(NULLIF(m.display_name, ''), m.email) AS display_name
FROM mk_costing_first_group_mail f
JOIN mk_mail m
  ON m.id = f.mail_id
  AND m.is_active = true
ORDER BY f.urun_ilk_grubu, m.email
`

const DeleteCostingFirstGroupMailsByGroup = `
DELETE FROM mk_costing_first_group_mail
WHERE urun_ilk_grubu = $1
`

const InsertCostingFirstGroupMailMapping = `
INSERT INTO mk_costing_first_group_mail (urun_ilk_grubu, mail_id)
VALUES ($1, $2)
`

const GetPricingFirstGroupMailMappingRows = `
SELECT
  f.urun_ilk_grubu,
  m.id::text,
  m.email,
  COALESCE(NULLIF(m.display_name, ''), m.email) AS display_name
FROM mk_pricing_first_group_mail f
JOIN mk_mail m
  ON m.id = f.mail_id
  AND m.is_active = true
ORDER BY f.urun_ilk_grubu, m.email
`

const DeletePricingFirstGroupMailsByGroup = `
DELETE FROM mk_pricing_first_group_mail
WHERE urun_ilk_grubu = $1
`

const InsertPricingFirstGroupMailMapping = `
INSERT INTO mk_pricing_first_group_mail (urun_ilk_grubu, mail_id)
VALUES ($1, $2)
`

const GetOrderPriceListFirstGroupMailMappingRows = `
SELECT
  f.urun_ilk_grubu,
  m.id::text,
  m.email,
  COALESCE(NULLIF(m.display_name, ''), m.email) AS display_name
FROM mk_order_price_list_first_group_mail f
JOIN mk_mail m
  ON m.id = f.mail_id
  AND m.is_active = true
ORDER BY f.urun_ilk_grubu, m.email
`

const DeleteOrderPriceListFirstGroupMailsByGroup = `
DELETE FROM mk_order_price_list_first_group_mail
WHERE urun_ilk_grubu = $1
`

const InsertOrderPriceListFirstGroupMailMapping = `
INSERT INTO mk_order_price_list_first_group_mail (urun_ilk_grubu, mail_id)
VALUES ($1, $2)
`
