-- 테스터 계정 (비밀번호: test1234!) — 관리자 회원 등록과 동일 필드 구성
-- 비밀번호 해시: PHP password_hash('test1234!', PASSWORD_DEFAULT)
-- tester_local → local_government 중구청 (lg_idx=10, lg_code=110201)
-- 실행 예: mysql -h 116.122.157.166 -P 3306 -u jongryangje -p jongryangje_dev < writable/database/seed_tester_accounts_trash_host.sql

SET NAMES utf8mb4;
SET @pw := '$2y$10$D.rk9Dtce7qitSCaPO0W2.DROcEwpe3otxE.QF0qWPb63bCBhtE5u';

START TRANSACTION;

DELETE mar FROM member_approval_request mar
INNER JOIN member m ON m.mb_idx = mar.mb_idx
WHERE m.mb_id IN ('tester_badmin', 'tester_admin', 'tester_local', 'tester_shop', 'tester_user');

INSERT INTO `member` (
  `mb_id`, `mb_passwd`, `mb_totp_secret`, `mb_totp_enabled`,
  `mb_name`, `mb_email`, `mb_phone`, `mb_lang`,
  `mb_level`, `mb_group`, `mb_lg_idx`, `mb_state`, `mb_regdate`
) VALUES
  ('tester_badmin', @pw, NULL, 0, '테스터본부', 'tester_badmin@test.com', '010-0000-0005', 'ko', 5, '', NULL, 1, NOW()),
  ('tester_admin',  @pw, NULL, 0, '테스터관리자', 'tester_admin@test.com', '010-0000-0001', 'ko', 4, '', NULL, 1, NOW()),
  ('tester_local',  @pw, NULL, 0, '테스터지자체(중구)', 'tester_local@test.com', '010-0000-0002', 'ko', 3, '', 10, 1, NOW()),
  ('tester_shop',   @pw, NULL, 0, '테스터판매소', 'tester_shop@test.com', '010-0000-0003', 'ko', 2, '', NULL, 1, NOW()),
  ('tester_user',   @pw, NULL, 0, '테스터사용자', 'tester_user@test.com', '010-0000-0004', 'ko', 1, '', NULL, 1, NOW())
AS new
ON DUPLICATE KEY UPDATE
  `mb_passwd`       = new.`mb_passwd`,
  `mb_totp_secret`  = NULL,
  `mb_totp_enabled` = 0,
  `mb_name`         = new.`mb_name`,
  `mb_email`        = new.`mb_email`,
  `mb_phone`        = new.`mb_phone`,
  `mb_level`        = new.`mb_level`,
  `mb_group`        = new.`mb_group`,
  `mb_lg_idx`       = new.`mb_lg_idx`,
  `mb_state`        = 1;

INSERT INTO `member_approval_request` (
  `mb_idx`, `mar_requested_level`, `mar_status`, `mar_request_note`,
  `mar_reject_reason`, `mar_requested_at`, `mar_requested_by`,
  `mar_processed_at`, `mar_processed_by`
)
SELECT
  m.`mb_idx`,
  m.`mb_level`,
  'approved',
  '테스트 계정 시드',
  NULL,
  NOW(),
  m.`mb_idx`,
  NOW(),
  m.`mb_idx`
FROM `member` m
WHERE m.`mb_id` IN ('tester_badmin', 'tester_admin', 'tester_local', 'tester_shop', 'tester_user');

COMMIT;
