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


import java.math.BigDecimal;
import java.util.Collection;

import org.jooq.Condition;
import org.jooq.Field;
import org.jooq.Name;
import org.jooq.PlainSQL;
import org.jooq.QueryPart;
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.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.jooq.impl.TableImpl;

import ru.micord.webbpm.ervu.business_metrics.db_beans.registration_change_address.RegistrationChangeAddress;
import ru.micord.webbpm.ervu.business_metrics.db_beans.registration_change_address.tables.records.ViewRecordsAboutRegistratedCitizenV2Record;


/**
 * This class is generated by jOOQ.
 */
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class ViewRecordsAboutRegistratedCitizenV2 extends TableImpl<ViewRecordsAboutRegistratedCitizenV2Record> {

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of
     * <code>registration_change_address.view_records_about_registrated_citizen_v2</code>
     */
    public static final ViewRecordsAboutRegistratedCitizenV2 VIEW_RECORDS_ABOUT_REGISTRATED_CITIZEN_V2 = new ViewRecordsAboutRegistratedCitizenV2();

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

    /**
     * The column
     * <code>registration_change_address.view_records_about_registrated_citizen_v2.applications_received_from_epgu_id</code>.
     */
    public final TableField<ViewRecordsAboutRegistratedCitizenV2Record, Long> APPLICATIONS_RECEIVED_FROM_EPGU_ID = createField(DSL.name("applications_received_from_epgu_id"), SQLDataType.BIGINT, this, "");

    /**
     * The column
     * <code>registration_change_address.view_records_about_registrated_citizen_v2.count_all</code>.
     */
    public final TableField<ViewRecordsAboutRegistratedCitizenV2Record, Long> COUNT_ALL = createField(DSL.name("count_all"), SQLDataType.BIGINT, this, "");

    /**
     * The column
     * <code>registration_change_address.view_records_about_registrated_citizen_v2.percent_registrated_by_app_vk</code>.
     */
    public final TableField<ViewRecordsAboutRegistratedCitizenV2Record, BigDecimal> PERCENT_REGISTRATED_BY_APP_VK = createField(DSL.name("percent_registrated_by_app_vk"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>registration_change_address.view_records_about_registrated_citizen_v2.percent_registrated_another_vk</code>.
     */
    public final TableField<ViewRecordsAboutRegistratedCitizenV2Record, BigDecimal> PERCENT_REGISTRATED_ANOTHER_VK = createField(DSL.name("percent_registrated_another_vk"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>registration_change_address.view_records_about_registrated_citizen_v2.count_registrated_by_app_vk</code>.
     */
    public final TableField<ViewRecordsAboutRegistratedCitizenV2Record, BigDecimal> COUNT_REGISTRATED_BY_APP_VK = createField(DSL.name("count_registrated_by_app_vk"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>registration_change_address.view_records_about_registrated_citizen_v2.count_registrated_another_vk</code>.
     */
    public final TableField<ViewRecordsAboutRegistratedCitizenV2Record, BigDecimal> COUNT_REGISTRATED_ANOTHER_VK = createField(DSL.name("count_registrated_another_vk"), SQLDataType.NUMERIC, this, "");

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

    private ViewRecordsAboutRegistratedCitizenV2(Name alias, Table<ViewRecordsAboutRegistratedCitizenV2Record> aliased, Field<?>[] parameters, Condition where) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.view("""
        create view "view_records_about_registrated_citizen_v2" as  SELECT applications_received_from_epgu.applications_received_from_epgu_id,
         ((applications_received_from_epgu.count_provided + applications_received_from_epgu.count_registration_refusal) + applications_received_from_epgu.count_refusal_provide_service) AS count_all,
         COALESCE(round((((applications_received_from_epgu.count_provided)::numeric * (100)::numeric) / NULLIF((((applications_received_from_epgu.count_provided + applications_received_from_epgu.count_registration_refusal) + applications_received_from_epgu.count_refusal_provide_service))::numeric, (0)::numeric))), (0)::numeric) AS percent_registrated_by_app_vk,
         COALESCE(round(((((applications_received_from_epgu.count_registration_refusal + applications_received_from_epgu.count_refusal_provide_service))::numeric * (100)::numeric) / NULLIF((((applications_received_from_epgu.count_provided + applications_received_from_epgu.count_registration_refusal) + applications_received_from_epgu.count_refusal_provide_service))::numeric, (0)::numeric))), (0)::numeric) AS percent_registrated_another_vk,
         (applications_received_from_epgu.count_provided)::numeric AS count_registrated_by_app_vk,
         ((applications_received_from_epgu.count_registration_refusal + applications_received_from_epgu.count_refusal_provide_service))::numeric AS count_registrated_another_vk
        FROM registration_change_address.applications_received_from_epgu;
        """), where);
    }

    /**
     * Create an aliased
     * <code>registration_change_address.view_records_about_registrated_citizen_v2</code>
     * table reference
     */
    public ViewRecordsAboutRegistratedCitizenV2(String alias) {
        this(DSL.name(alias), VIEW_RECORDS_ABOUT_REGISTRATED_CITIZEN_V2);
    }

    /**
     * Create an aliased
     * <code>registration_change_address.view_records_about_registrated_citizen_v2</code>
     * table reference
     */
    public ViewRecordsAboutRegistratedCitizenV2(Name alias) {
        this(alias, VIEW_RECORDS_ABOUT_REGISTRATED_CITIZEN_V2);
    }

    /**
     * Create a
     * <code>registration_change_address.view_records_about_registrated_citizen_v2</code>
     * table reference
     */
    public ViewRecordsAboutRegistratedCitizenV2() {
        this(DSL.name("view_records_about_registrated_citizen_v2"), null);
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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