create table domain (
    id int not null auto_increment,
    name char(255) default '' not null,
    json text default '' not null,
    user char(16) default '' not null,
    ex_date datetime,
    primary key (id),
    unique key indx1 (name)
);

create table host (
    id int not null auto_increment,
    name char(255) default '' not null,
    json text default '' not null,
    user char(16) default '' not null,
    primary key (id),
    unique key indx1 (name)
);

create table contact (
    id int not null auto_increment,
    name char(16) default '' not null,
    json text default '' not null,
    user char(16) default '' not null,
    primary key (id),
    unique key indx1 (name)
);

create table transfer (
    id int not null auto_increment,
    obj enum('contact','domain'),
    name char(255) default '' not null,
    password char(16) default '' not null,
    status enum('clientApproved',
                'clientCancelled',
                'clientRejected',
                'pending',
                'serverApproved',
                'serverCancelled') default 'pending' not null,
    re_id char(16) default '' not null,
    re_date datetime,
    ac_id char(16) default '' not null,
    ac_date datetime,
    price int default '0' not null,
    ex_date datetime,
    ack enum('no','yes') default 'no' not null,
    side enum('agent','registrar') default 'agent' not null,
    primary key (id),
    unique key indx1 (obj,name)
);

create table create_domain (
    id int not null auto_increment,
    name char(255) default '' not null,
    user char(16) default '' not null,
    price int default '0' not null,
    period int default '0' not null,
    cr_date datetime,
    ex_date datetime,
    primary key (id),
    index indx1 (name)
);

create table renew_domain (
    id int not null auto_increment,
    name char(255) default '' not null,
    user char(16) default '' not null,
    price int default '0' not null,
    period int default '0' not null,
    cr_date datetime,
    ex_date datetime,
    primary key (id),
    index indx1 (name)
);

create table autorenew_domain (
    id int not null auto_increment,
    name char(255) default '' not null,
    user char(16) default '' not null,
    price int default '0' not null,
    cr_date datetime,
    ex_date datetime,
    ack enum('no','yes'),
    primary key (id),
    index indx1 (name)
);

create table restore_domain (
    id int not null auto_increment,
    name char(255) default '' not null,
    user char(16) default '' not null,
    price int default '0' not null,
    cr_date datetime,
    ex_date datetime,
    primary key (id),
    index indx1 (name)
);

create table delete_domain (
    id int not null auto_increment,
    name char(255) default '' not null,
    json text default '' not null,
    user char(16) default '' not null,
    ex_date datetime,
    rm_date datetime,
    rs_date datetime,
    rgp enum('addPeriod','autoRenewPeriod','renewPeriod','transferPeriod','redemptionPeriod','pendingRestore','pendingDelete') default 'redemptionPeriod',
    oid int default '0' not null,
    primary key (id),
    index indx1 (name)
);

create table launch_domain (
    id int not null auto_increment,
    name char(255) default '' not null,
    json text default '' not null,
    user char(16) default '' not null,
    price int default '0' not null,
    period int default '0' not null,
    cr_date datetime,
    ex_date datetime,
    phase enum('sunrise','landrush','claims','open','custom') default 'sunrise' not null,
    ap_id char(255) default '' not null,
    status enum('pendingValidation','validated','invalid','pendingAllocation','allocated','rejected','custom') default 'pendingValidation' not null,
    primary key (id),
    index indx1 (name),
    unique key indx2 (ap_id)
);

create table bills (
    id int not null auto_increment,
    user char(16) default '' not null,
    op char(16) default '' not null,
    domain char(255) default '' not null,
    appID char(255) default '' not null,
    registrant char(16) default '' not null,
    opDate datetime,
    price int,
    period int,
    exDate datetime,
    oldID char(32) default '' not null,
    uniID char(32) default '' not null,
    ack enum('no','yes') default 'no' not null,
    primary key (id),
    index indx1 (user),
    unique key indx2 (uniID)
);

/*  payment.audits  */
create table audits (
    contactId varchar(16) default '' not null,
    email varchar(255) default '' not null,
    uniId varchar(32) default '' not null,
    dirty boolean default '0' not null,
    emailOk boolean default '0' not null,
    uniIdOk boolean default '0' not null,
    primary key (contactId),
    index indx1 (email),
    index indx2 (uniId)
);
