/*
 * This file is generated by jOOQ.
 */
package ru.micord.webbpm.ervu.business_metrics.db_beans.journal_log.tables;


import java.sql.Date;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.jooq.Check;
import org.jooq.Condition;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Identity;
import org.jooq.InverseForeignKey;
import org.jooq.Name;
import org.jooq.Path;
import org.jooq.PlainSQL;
import org.jooq.QueryPart;
import org.jooq.Record;
import org.jooq.SQL;
import org.jooq.Schema;
import org.jooq.Select;
import org.jooq.Stringly;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableOptions;
import org.jooq.UniqueKey;
import org.jooq.impl.DSL;
import org.jooq.impl.Internal;
import org.jooq.impl.SQLDataType;
import org.jooq.impl.TableImpl;

import ru.micord.webbpm.ervu.business_metrics.db_beans.journal_log.JournalLog;
import ru.micord.webbpm.ervu.business_metrics.db_beans.journal_log.Keys;
import ru.micord.webbpm.ervu.business_metrics.db_beans.journal_log.tables.records.UserOperationRecord;
import ru.micord.webbpm.ervu.business_metrics.db_beans.metrics.tables.Users.UsersPath;


/**
 * Журналирование. Операции пользователей по категориям/Анализ действий
 */
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class UserOperation extends TableImpl<UserOperationRecord> {

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of <code>journal_log.user_operation</code>
     */
    public static final UserOperation USER_OPERATION = new UserOperation();

    /**
     * The class holding records for this type
     */
    @Override
    public Class<UserOperationRecord> getRecordType() {
        return UserOperationRecord.class;
    }

    /**
     * The column <code>journal_log.user_operation.user_operation_id</code>.
     */
    public final TableField<UserOperationRecord, Long> USER_OPERATION_ID = createField(DSL.name("user_operation_id"), SQLDataType.BIGINT.nullable(false).identity(true), this, "");

    /**
     * The column <code>journal_log.user_operation.recruitment_id</code>.
     */
    public final TableField<UserOperationRecord, String> RECRUITMENT_ID = createField(DSL.name("recruitment_id"), SQLDataType.VARCHAR(36).nullable(false), this, "");

    /**
     * The column <code>journal_log.user_operation.user_id</code>.
     */
    public final TableField<UserOperationRecord, Long> USER_ID = createField(DSL.name("user_id"), SQLDataType.BIGINT, this, "");

    /**
     * The column <code>journal_log.user_operation.update_date</code>.
     */
    public final TableField<UserOperationRecord, Timestamp> UPDATE_DATE = createField(DSL.name("update_date"), SQLDataType.TIMESTAMP(0).nullable(false).defaultValue(DSL.field(DSL.raw("now()"), SQLDataType.TIMESTAMP)), this, "");

    /**
     * The column <code>journal_log.user_operation.info_date</code>.
     */
    public final TableField<UserOperationRecord, Date> INFO_DATE = createField(DSL.name("info_date"), SQLDataType.DATE.nullable(false), this, "");

    /**
     * The column <code>journal_log.user_operation.info_source</code>. USER - в
     * разрезе пользователей, VK - в разрезе ВК
     */
    public final TableField<UserOperationRecord, String> INFO_SOURCE = createField(DSL.name("info_source"), SQLDataType.VARCHAR.nullable(false), this, "USER - в разрезе пользователей, VK - в разрезе ВК");

    /**
     * The column <code>journal_log.user_operation.action_source</code>.
     * CATEGORY - Операции пользователей по категориям, ACTION_ANALYSIS - Анализ
     * действий
     */
    public final TableField<UserOperationRecord, String> ACTION_SOURCE = createField(DSL.name("action_source"), SQLDataType.VARCHAR.nullable(false), this, "CATEGORY - Операции пользователей по категориям, ACTION_ANALYSIS - Анализ действий");

    /**
     * The column <code>journal_log.user_operation.count_1</code>.
     */
    public final TableField<UserOperationRecord, Long> COUNT_1 = createField(DSL.name("count_1"), SQLDataType.BIGINT.nullable(false).defaultValue(DSL.field(DSL.raw("0"), SQLDataType.BIGINT)), this, "");

    /**
     * The column <code>journal_log.user_operation.count_2</code>.
     */
    public final TableField<UserOperationRecord, Long> COUNT_2 = createField(DSL.name("count_2"), SQLDataType.BIGINT.nullable(false).defaultValue(DSL.field(DSL.raw("0"), SQLDataType.BIGINT)), this, "");

    /**
     * The column <code>journal_log.user_operation.count_3</code>.
     */
    public final TableField<UserOperationRecord, Long> COUNT_3 = createField(DSL.name("count_3"), SQLDataType.BIGINT.nullable(false).defaultValue(DSL.field(DSL.raw("0"), SQLDataType.BIGINT)), this, "");

    private UserOperation(Name alias, Table<UserOperationRecord> aliased) {
        this(alias, aliased, (Field<?>[]) null, null);
    }

    private UserOperation(Name alias, Table<UserOperationRecord> aliased, Field<?>[] parameters, Condition where) {
        super(alias, null, aliased, parameters, DSL.comment("Журналирование. Операции пользователей по категориям/Анализ действий"), TableOptions.table(), where);
    }

    /**
     * Create an aliased <code>journal_log.user_operation</code> table reference
     */
    public UserOperation(String alias) {
        this(DSL.name(alias), USER_OPERATION);
    }

    /**
     * Create an aliased <code>journal_log.user_operation</code> table reference
     */
    public UserOperation(Name alias) {
        this(alias, USER_OPERATION);
    }

    /**
     * Create a <code>journal_log.user_operation</code> table reference
     */
    public UserOperation() {
        this(DSL.name("user_operation"), null);
    }

    public <O extends Record> UserOperation(Table<O> path, ForeignKey<O, UserOperationRecord> childPath, InverseForeignKey<O, UserOperationRecord> parentPath) {
        super(path, childPath, parentPath, USER_OPERATION);
    }

    /**
     * A subtype implementing {@link Path} for simplified path-based joins.
     */
    public static class UserOperationPath extends UserOperation implements Path<UserOperationRecord> {
        public <O extends Record> UserOperationPath(Table<O> path, ForeignKey<O, UserOperationRecord> childPath, InverseForeignKey<O, UserOperationRecord> parentPath) {
            super(path, childPath, parentPath);
        }
        private UserOperationPath(Name alias, Table<UserOperationRecord> aliased) {
            super(alias, aliased);
        }

        @Override
        public UserOperationPath as(String alias) {
            return new UserOperationPath(DSL.name(alias), this);
        }

        @Override
        public UserOperationPath as(Name alias) {
            return new UserOperationPath(alias, this);
        }

        @Override
        public UserOperationPath as(Table<?> alias) {
            return new UserOperationPath(alias.getQualifiedName(), this);
        }
    }

    @Override
    public Schema getSchema() {
        return aliased() ? null : JournalLog.JOURNAL_LOG;
    }

    @Override
    public Identity<UserOperationRecord, Long> getIdentity() {
        return (Identity<UserOperationRecord, Long>) super.getIdentity();
    }

    @Override
    public UniqueKey<UserOperationRecord> getPrimaryKey() {
        return Keys.USER_OPERATION_PKEY;
    }

    @Override
    public List<ForeignKey<UserOperationRecord, ?>> getReferences() {
        return Arrays.asList(Keys.USER_OPERATION__FK_USER_ID);
    }

    private transient UsersPath _users;

    /**
     * Get the implicit join path to the <code>metrics.users</code> table.
     */
    public UsersPath users() {
        if (_users == null)
            _users = new UsersPath(this, Keys.USER_OPERATION__FK_USER_ID, null);

        return _users;
    }

    @Override
    public List<Check<UserOperationRecord>> getChecks() {
        return Arrays.asList(
            Internal.createCheck(this, DSL.name("chk_action_source"), "(((action_source)::text = ANY (ARRAY[('CATEGORY'::character varying)::text, ('ACTION_ANALYSIS'::character varying)::text])))", true),
            Internal.createCheck(this, DSL.name("chk_info_source"), "(((((info_source)::text = 'USER'::text) AND (user_id IS NOT NULL)) OR ((info_source)::text = 'VK'::text)))", true)
        );
    }

    @Override
    public UserOperation as(String alias) {
        return new UserOperation(DSL.name(alias), this);
    }

    @Override
    public UserOperation as(Name alias) {
        return new UserOperation(alias, this);
    }

    @Override
    public UserOperation as(Table<?> alias) {
        return new UserOperation(alias.getQualifiedName(), this);
    }

    /**
     * Rename this table
     */
    @Override
    public UserOperation rename(String name) {
        return new UserOperation(DSL.name(name), null);
    }

    /**
     * Rename this table
     */
    @Override
    public UserOperation rename(Name name) {
        return new UserOperation(name, null);
    }

    /**
     * Rename this table
     */
    @Override
    public UserOperation rename(Table<?> name) {
        return new UserOperation(name.getQualifiedName(), null);
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public UserOperation where(Condition condition) {
        return new UserOperation(getQualifiedName(), aliased() ? this : null, null, condition);
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public UserOperation where(Collection<? extends Condition> conditions) {
        return where(DSL.and(conditions));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public UserOperation where(Condition... conditions) {
        return where(DSL.and(conditions));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public UserOperation where(Field<Boolean> condition) {
        return where(DSL.condition(condition));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public UserOperation where(SQL condition) {
        return where(DSL.condition(condition));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public UserOperation where(@Stringly.SQL String condition) {
        return where(DSL.condition(condition));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public UserOperation where(@Stringly.SQL String condition, Object... binds) {
        return where(DSL.condition(condition, binds));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public UserOperation where(@Stringly.SQL String condition, QueryPart... parts) {
        return where(DSL.condition(condition, parts));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public UserOperation whereExists(Select<?> select) {
        return where(DSL.exists(select));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public UserOperation whereNotExists(Select<?> select) {
        return where(DSL.notExists(select));
    }
}
