GOPATH=$(shell go env GOPATH)
export GOPATH

setup:
	brew install protobuf
	brew tap alecthomas/homebrew-tap
	brew install golangci/tap/golangci-lint
	brew install clang-format
	brew install dep
	brew install terraform
	go get -u github.com/golang/protobuf/protoc-gen-go/...
	git -C $(GOPATH)/src/github.com/golang/protobuf checkout v1.2.0 # Change version as needed. This will check out the desired version and install it.
	go install github.com/golang/protobuf/protoc-gen-go
	git -C $(GOPATH)/src/github.com/golang/protobuf checkout master
	go get -u github.com/twitchtv/twirp/protoc-gen-twirp/...
	go get github.com/golang/mock/gomock
	go install github.com/golang/mock/mockgen
	go get github.com/gogo/protobuf/protoc-gen-gogofaster
	go get github.com/gogo/protobuf/gogoproto
.PHONY: setup

update:
	dep ensure
.PHONY: update

test:
	go test -cover -race -v ./...
.PHONY: test

lint:
	golangci-lint run
.PHONY: lint

build-setup:
	@wget -O - -q https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
.PHONY: build-setup

build: build-setup lint test
.PHONY: build

proto-lint:
	clang-format -style="{BasedOnStyle: Google, IndentWidth: 4}" -verbose -i rpc/dropship/*.proto
.PHONY: proto-lint

proto:
	protoc -I=. -I=$(GOPATH)/src -I=$(GOPATH)/src/github.com/gogo/protobuf --gogofaster_out=. --twirp_out=. ./rpc/dropship/service.proto
	cat rpc/dropship/service.pb.go | sed 's/,omitempty//' | sed 's/omitempty//' > rpc/dropship/service.pb.go.temp && mv rpc/dropship/service.pb.go.temp rpc/dropship/service.pb.go
.PHONY: proto

mocks:
	mockgen -destination ./internal/mocks/dynamodb/dynamodb.go code.justin.tv/cb/dropship/internal/clients/dynamodb Database
	mockgen -destination ./internal/mocks/stats/stats.go code.justin.tv/cb/dropship/internal/clients/stats StatSender
	mockgen -destination ./internal/mocks/ripley/ripley.go code.justin.tv/cb/dropship/internal/clients/ripley Payouts
.PHONY: mocks

PORT ?= "8080"
ENVIRONMENT ?= "development"
REGION ?= "us-west-2"
LAYOUT_TABLE_NAME ?= "dropship-staging-quick-actions-layout"
STATS_HOST ?= "statsd.central.twitch.a2z.com:8125"
RIPLEY_HOST ?= "http://beta.ripley.twitch.a2z.com"

run:
	PORT=$(PORT) \
	ENVIRONMENT=$(ENVIRONMENT) \
	REGION=$(REGION) \
	LAYOUT_TABLE_NAME=$(LAYOUT_TABLE_NAME) \
	STATS_HOST=$(STATS_HOST) \
	RIPLEY_HOST=$(RIPLEY_HOST) \
	go run ./cmd/dropshipserver/main.go
.PHONY: run
