// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.25.0
// source: stats.sql

package db

import (
	"context"
)

const CalculateASNStats = `-- name: CalculateASNStats :exec
SELECT update_asn_metrics()
`

func (q *Queries) CalculateASNStats(ctx context.Context) error {
	_, err := q.db.Exec(ctx, CalculateASNStats)
	return err
}

const CalculateCountryStats = `-- name: CalculateCountryStats :exec
SELECT update_country_metrics()
`

func (q *Queries) CalculateCountryStats(ctx context.Context) error {
	_, err := q.db.Exec(ctx, CalculateCountryStats)
	return err
}

const CrawlerStats = `-- name: CrawlerStats :one
SELECT
 count(1) AS "domains",
 count(1) filter (WHERE base_domain = 'supported') AS "base_domain",
 count(1) filter (WHERE www_domain = 'supported') AS "www_domain",
 count(1) filter (WHERE nameserver = 'supported') AS "nameserver",
 count(1) filter (WHERE mx_record = 'supported') AS "mx_record",
 count(1) filter (WHERE base_domain = 'supported' AND www_domain = 'supported') AS "heroes",
 count(1) filter (WHERE base_domain != 'unsupported' AND www_domain != 'unsupported' AND rank < 1000) AS "top_heroes",
 count(1) filter (WHERE nameserver = 'supported' AND rank < 1000) AS "top_nameserver"
FROM domain_view_list
`

type CrawlerStatsRow struct {
	Domains       int64
	BaseDomain    int64
	WwwDomain     int64
	Nameserver    int64
	MxRecord      int64
	Heroes        int64
	TopHeroes     int64
	TopNameserver int64
}

// Used by the crawler to store total stats in the metric table
func (q *Queries) CrawlerStats(ctx context.Context) (CrawlerStatsRow, error) {
	row := q.db.QueryRow(ctx, CrawlerStats)
	var i CrawlerStatsRow
	err := row.Scan(
		&i.Domains,
		&i.BaseDomain,
		&i.WwwDomain,
		&i.Nameserver,
		&i.MxRecord,
		&i.Heroes,
		&i.TopHeroes,
		&i.TopNameserver,
	)
	return i, err
}
